@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { log.error("Can't handshake " + sessionId, future.cause()); return; } channel.pipeline().addBefore(SocketIOChannelInitializer.WEB_SOCKET_TRANSPORT, SocketIOChannelInitializer.WEB_SOCKET_AGGREGATOR, new WebSocketFrameAggregator(configuration.getMaxFramePayloadLength())); connectClient(channel, sessionId); } });
@Override protected boolean isAggregated(WebSocketFrame msg) throws Exception { if (msg.isFinalFragment()) { return !isContentMessage(msg); } return !isStartMessage(msg) && !isContentMessage(msg); }
@Override protected boolean isLastContentMessage(ContinuationWebSocketFrame msg) throws Exception { return isContentMessage(msg) && msg.isFinalFragment(); }
@Override protected boolean isLastContentMessage(ContinuationWebSocketFrame msg) throws Exception { return isContentMessage(msg) && msg.isFinalFragment(); }
private void switchToWebsocket( ChannelHandlerContext ctx ) { ChannelPipeline p = ctx.pipeline(); p.addLast( new HttpServerCodec(), new HttpObjectAggregator( MAX_WEBSOCKET_HANDSHAKE_SIZE ), new WebSocketServerProtocolHandler( "/", null, false, MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameAggregator( MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameTranslator(), newHandshaker() ); p.remove( this ); }
@Override protected boolean isAggregated(WebSocketFrame msg) throws Exception { if (msg.isFinalFragment()) { return !isContentMessage(msg); } return !isStartMessage(msg) && !isContentMessage(msg); }
@Override protected boolean isLastContentMessage(ContinuationWebSocketFrame msg) throws Exception { return isContentMessage(msg) && msg.isFinalFragment(); }
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) { pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); pipeline.addAfter(WS_ENCODER_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, config.isEnableWebSocketCompression(), config.getWebSocketMaxFrameSize())); if (config.isAggregateWebSocketFrameFragments()) { pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize())); } pipeline.remove(HTTP_CLIENT_CODEC); }
@Override protected boolean isAggregated(WebSocketFrame msg) throws Exception { if (msg.isFinalFragment()) { return !isContentMessage(msg); } return !isStartMessage(msg) && !isContentMessage(msg); }
@Override protected boolean isLastContentMessage(ContinuationWebSocketFrame msg) throws Exception { return isContentMessage(msg) && msg.isFinalFragment(); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { log.error("Can't handshake " + sessionId, future.cause()); return; } channel.pipeline().addBefore(SocketIOChannelInitializer.WEB_SOCKET_TRANSPORT, SocketIOChannelInitializer.WEB_SOCKET_AGGREGATOR, new WebSocketFrameAggregator(configuration.getMaxFramePayloadLength())); connectClient(channel, sessionId); } });
@Override protected boolean isAggregated(WebSocketFrame msg) throws Exception { if (msg.isFinalFragment()) { return !isContentMessage(msg); } return !isStartMessage(msg) && !isContentMessage(msg); }
@Override protected boolean isLastContentMessage(ContinuationWebSocketFrame msg) throws Exception { return isContentMessage(msg) && msg.isFinalFragment(); }
@Override public void operationComplete(ChannelFuture future) throws Exception { final String sessionId = PipelineUtils.getSessionId(requestPath); if (future.isSuccess()) { ctx.channel().pipeline().addBefore( SocketIOChannelInitializer.SOCKETIO_WEBSOCKET_HANDLER, SocketIOChannelInitializer.WEBSOCKET_FRAME_AGGREGATOR, new WebSocketFrameAggregator(maxWebSocketFrameSize)); connect(ctx, req, sessionId); } else { log.error("Can't handshake: {}", sessionId, future.cause()); } } });
@Override protected boolean isAggregated(WebSocketFrame msg) throws Exception { if (msg.isFinalFragment()) { return !isContentMessage(msg); } return !isStartMessage(msg) && !isContentMessage(msg); }
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { context().addHandlerLast(new WebSocketFrameAggregator(maxContentLength)); return this; }
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { withConnection(c -> c.addHandlerLast(new WebSocketFrameAggregator(maxContentLength))); return this; }
/** * Turn this {@link WebsocketInbound} into aggregating mode which will only produce * fully formed frame that have been received fragmented. * * @param maxContentLength the maximum frame length * * @return this inbound */ default WebsocketInbound aggregateFrames(int maxContentLength) { withConnection(c -> c.addHandlerLast(new WebSocketFrameAggregator(maxContentLength))); return this; }
private void switchToWebsocket( ChannelHandlerContext ctx ) { ChannelPipeline p = ctx.pipeline(); p.addLast( new HttpServerCodec(), new HttpObjectAggregator( MAX_WEBSOCKET_HANDSHAKE_SIZE ), new WebSocketServerProtocolHandler( "/", null, false, MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameAggregator( MAX_WEBSOCKET_FRAME_SIZE ), new WebSocketFrameTranslator(), newHandshaker() ); p.remove( this ); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception{ if(evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE){ NettyWebSocket webSocket = new NettyWebSocket(null, handshaker.actualSubprotocol()); ctx.pipeline().addLast("ws-aggregator", new WebSocketFrameAggregator(16 * 1024 * 1024)); // 16MB ctx.pipeline().addLast("websocket", webSocket); ctx.pipeline().remove(this); webSocket.channelActive(ctx); connectListener.onConnect(webSocket); }else ctx.fireUserEventTriggered(evt); } }