【发布时间】: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