Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Netty ChannelHandlerContext.write()不工作_C#_Netty - Fatal编程技术网

C# Netty ChannelHandlerContext.write()不工作

C# Netty ChannelHandlerContext.write()不工作,c#,netty,C#,Netty,我正在和Netty写一个服务器。不幸的是,write或writeAndFlush方法对我不起作用 我有一个扩展ChannelDuplexHandler的处理程序。它接收来自C客户机的消息,打印它们并发送回消息。客户端从未收到消息,因此我不知道它们是否真的被发送 @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { String input = msg.toString(); Syste

我正在和Netty写一个服务器。不幸的是,write或writeAndFlush方法对我不起作用

我有一个扩展ChannelDuplexHandler的处理程序。它接收来自C客户机的消息,打印它们并发送回消息。客户端从未收到消息,因此我不知道它们是否真的被发送

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
{
    String input = msg.toString();
    System.out.println("Input = " + input); // This works fine
    ctx.writeAndFlush("Test");
    ctx.write("Test 1 2 3"); // This doesn't work.
}
这是我的管道:

public void initChannel(SocketChannel ch) throws Exception 
{
    ch.pipeline().addLast("idleStateHandler", ish);
    ch.pipeline().addLast("frameDecoder", new LineBasedFrameDecoder(maxIncMessageLength));
    ch.pipeline().addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
    ch.pipeline().addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
    ch.pipeline().addLast("myChannelDuplexHandler", gsh);
}
所以我的问题是,为什么写不起作用?谢谢

编辑:出于测试目的,我刚刚添加了

    final ChannelFuture f = ctx.writeAndFlush("Test"); 
    if(f.isDone())
        System.out.println("done!");
    if(f.isSuccess())
        System.out.println("real success!");
    f.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) {
            System.out.println("complete!");
        }
    }); 
结果是: 完成! 真正的成功! 完成


问题可能出在客户端吗?

实际上似乎是客户端的问题。到目前为止,我使用的StreamReader还不起作用,但如果我只是按字节顺序阅读,我会得到输入。好像你忘记添加换行符了?”\不