に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
}
}