0
我一直在使用Netty,但主要是爲了使用正常的套接字時,他們的渠道總是唯一的,因此我可以映射渠道知道誰連接到我的服務器。Netty ChannelHandlerContext不是唯一的嗎?
現在我設法實現了http通信。問題是ChannelHandlerContext處理程序的值(以及來自那些處理程序的通道)不是唯一的,我無法檢測到誰正在通過它們的處理程序連接。
問題:
是該行爲(ChannelHandlerContext處理值不 唯一的)正常或我有一些代碼錯誤?
任何想法,解決方案?
非常感謝
我ChannelInitializer如下所示:
public class NettyHttpServerInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("http", new HttpServerCodec()));
pipeline.addLast("dechunker", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new HttpServerHandler());
}
}
我的服務器處理器看起來CTX和ctx.channel的(值()不是唯一的,甚至來自同一客戶端觸發):
public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
@Override
protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
...
}
}
再次感謝:) – Tony