Created
December 22, 2013 11:47
-
-
Save melin/8081255 to your computer and use it in GitHub Desktop.
netty server client handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChannelInboundHandlerAdapter | |
@Override | |
public void channelRead(ChannelHandlerContext ctx, Object msg) { | |
System.out.println(ìServer received: ì + msg); | |
ctx.write(msg) #2 | |
} | |
@Override | |
public void channelReadComplete(ChannelHandlerContext ctx) { | |
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER) | |
.addListener(ChannelFutureListener.CLOSE); #3 | |
} | |
@Override | |
public void exceptionCaught(ChannelHandlerContext ctx, | |
Throwable cause) { | |
cause.printStracktrace(); #4 | |
ctx.close(); #5 | |
} | |
SimpleChannelInboundHandlerAdapter | |
@Override | |
public void channelActive(ChannelHandlerContext ctx) { | |
ctx.write(Unpooled.copiedBuffer(ìNetty rocks!ì, | |
CharsetUtil.UTF_8); #2 | |
} | |
@Override | |
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) { | |
System.out.println(ìClient received: ì + ByteBufUtil | |
.hexDump(in.readBytes(in.readableBytes()))); | |
} | |
@Override | |
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { | |
cause.printStracktrace(); | |
ctx.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment