io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator Java Examples
The following examples show how to use
io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InboundWebsocketChannelInitializer.java From micro-integrator with Apache License 2.0 | 6 votes |
@Override protected void initChannel(SocketChannel websocketChannel) throws Exception { if (sslConfiguration != null) { SslHandler sslHandler = new SSLHandlerFactory(sslConfiguration).create(); websocketChannel.pipeline().addLast("ssl", sslHandler); } ChannelPipeline p = websocketChannel.pipeline(); p.addLast("codec", new HttpServerCodec()); p.addLast("aggregator", new HttpObjectAggregator(65536)); p.addLast("frameAggregator", new WebSocketFrameAggregator(Integer.MAX_VALUE)); InboundWebsocketSourceHandler sourceHandler = new InboundWebsocketSourceHandler(); sourceHandler.setClientBroadcastLevel(clientBroadcastLevel); sourceHandler.setDispatchToCustomSequence(dispatchToCustomSequence); sourceHandler.setPortOffset(portOffset); if (outflowDispatchSequence != null) sourceHandler.setOutflowDispatchSequence(outflowDispatchSequence); if (outflowErrorSequence != null) sourceHandler.setOutflowErrorSequence(outflowErrorSequence); if (subprotocolHandlers != null) sourceHandler.setSubprotocolHandlers(subprotocolHandlers); if (pipelineHandler != null) p.addLast("pipelineHandler", pipelineHandler.getClass().getConstructor().newInstance()); p.addLast("handler", sourceHandler); }
Example #2
Source File: WebSocketHandler.java From socketio with Apache License 2.0 | 6 votes |
private void handshake(final ChannelHandlerContext ctx, final FullHttpRequest req, final String requestPath) { WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true, maxWebSocketFrameSize); WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req); if (handshaker != null) { handshaker.handshake(ctx.channel(), req).addListener( new ChannelFutureListener() { @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()); } } }); } else { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); } }
Example #3
Source File: NettyServerForUi.java From bistoury with GNU General Public License v3.0 | 5 votes |
@Override public void start() { ServerBootstrap bootstrap = new ServerBootstrap() .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, DEFAULT_WRITE_LOW_WATER_MARK) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, DEFAULT_WRITE_HIGH_WATER_MARK) .channel(NioServerSocketChannel.class) .group(BOSS, WORKER) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pip = ch.pipeline(); pip.addLast(new IdleStateHandler(0, 0, 30 * 60 * 1000)) .addLast(new HttpServerCodec()) .addLast(new HttpObjectAggregator(1024 * 1024)) .addLast(new WebSocketServerProtocolHandler("/ws")) .addLast(new WebSocketFrameAggregator(1024 * 1024 * 1024)) .addLast(new RequestDecoder(new DefaultRequestEncryption(new RSAEncryption()))) .addLast(new WebSocketEncoder()) .addLast(new TabHandler()) .addLast(new HostsValidatorHandler(serverFinder)) .addLast(new UiRequestHandler( commandStore, uiConnectionStore, agentConnectionStore, sessionManager)); } }); try { this.channel = bootstrap.bind(port).sync().channel(); logger.info("client server startup successfully, port {}", port); } catch (Exception e) { logger.error("netty server for ui start fail", e); throw Throwables.propagate(e); } }
Example #4
Source File: PortUnificationServerHandler.java From sctalk with Apache License 2.0 | 5 votes |
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline pipeline = ctx.pipeline(); pipeline.addLast("http-codec", new HttpServerCodec()); pipeline.addLast("aggregator", new WebSocketFrameAggregator(65536)); // Http消息组装 pipeline.addLast("http-chunked", new ChunkedWriteHandler()); // WebSocket通信支持 pipeline.addLast("decoder", new PacketWsFrameDecoder()); pipeline.addLast("encoder", new PacketWsFrameEncoder()); pipeline.addLast("handler", new MessageWsServerHandler(handlerManager)); pipeline.remove(this); }
Example #5
Source File: WebsocketInbound.java From reactor-netty with Apache License 2.0 | 2 votes |
/** * 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(NettyPipeline.WsFrameAggregator, new WebSocketFrameAggregator(maxContentLength))); return this; }