I\'m trying to make my first steps with Netty, for this purpose I wrote simple server on Netty and simple client on oio plain TCP.
Client sends random text packet, a
You will see why it fails if you replace your
ctx.write("Ack");
ctx.flush();
in your serverHandler with the following:
ChannelFuture cf = ctx.write("Ack");
ctx.flush();
if (!cf.isSuccess()) {
System.out.println("Send failed: " + cf.cause());
}
It should give you a message saying that String
is not supported.
ByteBuf
should work though:
ctx.write(Unpooled.copiedBuffer("Ack", CharsetUtil.UTF_8));
ctx.flush();
on the client side edit the channelRead method:
ByteBuf in = (ByteBuf) msg;
System.out.println("Client received: " + in.toString(CharsetUtil.UTF_8));