2015-04-21 37 views
2

如何从客户端得到数据immediantly在服务器网状4.如何从客户端直接读取数据?

在那一刻,我将数据发送到客户端,客户端送我data.But处理程序(方法channelRead())收到后才服务器sended数据数据

我将在进程列表中的问题,我用网状4:

  1. 从客户
  2. 开始计算响应
  3. 获取数据的一些业务数据发送到客户端为(ctx.writeAndFlush())(OK)
  4. 继续从客户端计算响应
  5. 应该得到的数据(这里有一个问题)
  6. 发送计算响应客户端(发送OK)。

我的代码: 处理器

@Override 
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 

     logger.debug("Start read handler " + ctx.channel().toString()); 
     ByteBuf b = (ByteBuf) msg; 
    ctx.write(Unpooled.copiedBuffer(new Test.send(ctx,b)); 
} 

测试

public class Test 
public byte[] send(ChannelHandlerContext ctx,ByteBuf b){ 
// start calculates 
ctx.writeAndFlush(Unpooled.copiedBuffer(some data)); - its ok 

// calculates .. (during here i should get data from client but nothing happens. Why does the channel blocks receiving data ?) 
return response; 

} 

回答

2

你应该有一旦收到答复,将被通知ChannelInboundHandler。记住netty中的所有内容都是非阻塞的。

相关问题