new ServerBootstrap().group(group)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel socketChannel) {
final long startTime = System.currentTimeMillis();
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void read(ChannelHandlerContext ctx) {
ctx.writeAndFlush(Unpooled.wrappedBuffer("Hello!".getBytes()));
.addListener(ChannelFutureListener.CLOSE);
}
});
ChannelFuture f = socketChannel.closeFuture();
f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
System.out.println(System.currentTimeMillis() - startTime);
}
});
}
})
.bind("localhost", 1025)
.sync()
.channel()
.closeFuture()
.syncUninterruptibly();