【问题标题】:My netty client program is not receiving any response from server我的 netty 客户端程序没有收到来自服务器的任何响应
【发布时间】:2018-08-20 12:00:52
【问题描述】:

我使用 netty IO 编写了一个客户端-服务器程序,在该程序中我可以向服务器发送消息,服务器会做出响应,但不幸的是,我的客户端处理程序类中的任何侦听器方法都没有被调用,即..在客户端级别没有收到响应。这是我的客户端用来向服务器发送请求消息的一段代码。

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());
} 

以下是用于从服务器接收任何响应消息的代码。

 @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());

}

但是这个方法根本没有被调用。

【问题讨论】:

  • 你的管道是什么样的?
  • 感谢您的评论!我只有一个处理程序,仅此而已。但是处理程序中的任何回调方法都不会被调用。

标签: java server socket.io client netty


【解决方案1】:

您的处理程序是从什么扩展而来的?如果要从服务器接收响应,它应该是一个入站处理程序。您确定您的代码使用@Override 注释进行编译吗? ChannelInboundHanlder中的回调方法是public void void channelRead(ChannelHandlerContext ctx, Object msg)。确保使用 @Override 进行注释并确保代码编译。然后您的客户端将/应该收到来自服务器的响应。如果没有帮助,请考虑共享完整代码。

【讨论】:

    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    相关资源
    最近更新 更多