// Phew. Ok. We built all that. Now what ?
InetSocketAddress addressToConnectTo = new InetSocketAddress("localhost", 8080);
//ChannelFuture cf = bootstrap.connect(addressToConnectTo);
clog("Issuing Channel Connect...");
// Waiting on a connect. (Pick one)
ChannelFuture cf = bootstrap.connect(addressToConnectTo);
// wait interruptibly
// cf.await();
// wait interruptibly with a timeout of 2000 ms.
// cf.await(2000, TimeUnit.MILLISECONDS);
// wait uninterruptibly
clog("Waiting for Channel Connect...");
cf.awaitUninterruptibly();
// wait uninterruptibly with a timeout of 2000 ms.
// cf.awaitUninterruptibly(2000, TimeUnit.MILLISECONDS);
// add a ChannelFutureListener that writes the Date when the connect is complete
// cf.addListener(new ChannelFutureListener(){
// public void operationComplete(ChannelFuture future) throws Exception {
// // chek to see if we succeeded
// if(future.isSuccess()) {
// Channel channel = future.getChannel();
// channel.write(new Date());
// // remember, the write is asynchronous too !
// }
// }
// });
// if a wait option was selected and the connect did not fail,
// the Date can now be sent.
clog("Connected. Sending Date");
Channel channel = cf.getChannel();
channel.write(new Date());
} catch (Exception e) {
e.printStackTrace(System.err);
}
}