2017-06-29 1 views
0

にChannelHandlerContext間でユーザーを識別:、私はユーザーを特定する方法を見つけ出すことはできませんネッティーWebSocketを

class WebSocketServerInitializer extends ChannelInitializer<SocketChannel> { 
@Override 
    public void initChannel(SocketChannel ch) throws Exception {     

      ChannelPipeline pipeline = ch.pipeline(); 

      pipeline.addLast(new HttpServerCodec()); 
      pipeline.addLast(new HttpObjectAggregator(65536)); 
      pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true)); 
      pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH)); 
      pipeline.addLast(new WebSocketFrameHandler()); 
      pipeline.addLast(new SessionManagerAxx()); 

    } 
} 

LoggingHandler:

class SessionManagerAxx extends LoggingHandler { 

    @Override 
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 

      if (evt.equals(ServerHandshakeStateEvent.HANDSHAKE_COMPLETE)) { 
        ///add the user 
        Clients.getInstance().addNewClient(ctx); 
      } 

      super.userEventTriggered(ctx, evt); 
    } 
} 

フレームハンドラー:

class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> { 

    private static final Logger logger = LoggerFactory.getLogger(WebSocketFrameHandler.class); 

    @Override 
    protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { 
     Clients.getInstance().getClient(ctx); 
     //Handle user msg 
    } 
} 

答えて

0

の「国家管理」に記載されています。

0

Channel.attr(...)に変換し、両方のハンドラで使用します。

0

認証は、だから私は、単一のクラスでFrameHandlerとSessionManagerの入社問題を解決したパイプライン内のノードがChannelHandlerContext を共有していないようだChannelHandler javadoc

関連する問題