Reputation: 13
I have written a client-server programme using netty IO in which I am able to send a message to the server and server responds back but unfortunately, any of the listener methods in my Client Handler class is not getting invoked ie.. response is not received at the client level back. This is the piece of code used in my client to send a request message to the server.
ChannelFuture cf =this.ctx.channel().writeAndFlush(Unpooled.copiedBuffer(getEchoISOMessage(), CharsetUtil.ISO_8859_1));
this.ctx.writeAndFlush(Unpooled.EMPTY_BUFFER);
cf.awaitUninterruptibly();
if (!cf.isSuccess()) {
System.out.println("Send failed: " + cf.cause());
}
Below is the code used to receive any response message from the server.
@Override
public void ChannelRead(ChannelHandlerContext ctx, ByteBuf in)
{
System.out.println("Received a response from Server..");
String responseMessage="";
responseMessage=in.toString(CharsetUtil.ISO_8859_1);
System.out.println("Received data as echo response"+responseMessage+"from "+ctx.channel().remoteAddress());
}
But this method is not getting invoked at all.
Upvotes: 0
Views: 1007
Reputation: 725
What does your handler extend from? It should be an inbound handler if it is to receive a response from the server. Are you sure your code compiles with the @Override
annotation? The callback method in ChannelInboundHanlder
is public void void channelRead(ChannelHandlerContext ctx, Object msg)
. Make sure your annotate with @Override
and make sure the code compiles. Then your client will/should receive the response from the server. If it doesn't help, consider sharing the full code.
Upvotes: 1