Search in sources :

Example 1 with WebSocketFrameAggregator

use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project netty-socketio by mrniko.

the class WebSocketTransport method handshake.

private void handshake(ChannelHandlerContext ctx, final UUID sessionId, String path, FullHttpRequest req) {
    final Channel channel = ctx.channel();
    WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, true, configuration.getMaxFramePayloadLength());
    WebSocketServerHandshaker handshaker = factory.newHandshaker(req);
    if (handshaker != null) {
        ChannelFuture f = handshaker.handshake(channel, req);
        f.addListener(new ChannelFutureListener() {

            @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);
            }
        });
    } else {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) WebSocketServerHandshaker(io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker) Channel(io.netty.channel.Channel) WebSocketServerHandshakerFactory(io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory) ChannelFutureListener(io.netty.channel.ChannelFutureListener)

Example 2 with WebSocketFrameAggregator

use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project async-http-client by AsyncHttpClient.

the class ChannelManager method upgradePipelineForWebSockets.

public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
    pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
    pipeline.addBefore(AHC_WS_HANDLER, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize()));
    pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize()));
    pipeline.remove(HTTP_CLIENT_CODEC);
}
Also used : WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) WebSocket08FrameDecoder(io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder) WebSocket08FrameEncoder(io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder)

Example 3 with WebSocketFrameAggregator

use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project intellij-community by JetBrains.

the class WebSocketHandshakeHandler method handleWebSocketRequest.

private void handleWebSocketRequest(@NotNull final ChannelHandlerContext context, @NotNull FullHttpRequest request, @NotNull final QueryStringDecoder uriDecoder) {
    WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory("ws://" + request.headers().getAsString(HttpHeaderNames.HOST) + uriDecoder.path(), null, false, NettyUtil.MAX_CONTENT_LENGTH);
    WebSocketServerHandshaker handshaker = factory.newHandshaker(request);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(context.channel());
        return;
    }
    if (!context.channel().isOpen()) {
        return;
    }
    final Client client = new WebSocketClient(context.channel(), handshaker);
    context.channel().attr(ClientManagerKt.getCLIENT()).set(client);
    handshaker.handshake(context.channel(), request).addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                ClientManager clientManager = WebSocketHandshakeHandler.this.clientManager.getValue();
                clientManager.addClient(client);
                MessageChannelHandler messageChannelHandler = new MessageChannelHandler(clientManager, getMessageServer());
                BuiltInServer.replaceDefaultHandler(context, messageChannelHandler);
                ChannelHandlerContext messageChannelHandlerContext = context.pipeline().context(messageChannelHandler);
                context.pipeline().addBefore(messageChannelHandlerContext.name(), "webSocketFrameAggregator", new WebSocketFrameAggregator(NettyUtil.MAX_CONTENT_LENGTH));
                messageChannelHandlerContext.channel().attr(ClientManagerKt.getCLIENT()).set(client);
                connected(client, uriDecoder.parameters());
            }
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) WebSocketServerHandshaker(io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker) WebSocketServerHandshakerFactory(io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelFutureListener(io.netty.channel.ChannelFutureListener)

Example 4 with WebSocketFrameAggregator

use of io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator in project spring-framework by spring-projects.

the class RxNettyWebSocketSession method aggregateFrames.

/**
	 * Insert an {@link WebSocketFrameAggregator} after the
	 * {@code WebSocketFrameDecoder} for receiving full messages.
	 * @param channel the channel for the session
	 * @param frameDecoderName the name of the WebSocketFrame decoder
	 */
public RxNettyWebSocketSession aggregateFrames(Channel channel, String frameDecoderName) {
    ChannelPipeline pipeline = channel.pipeline();
    if (pipeline.context(FRAME_AGGREGATOR_NAME) != null) {
        return this;
    }
    ChannelHandlerContext frameDecoder = pipeline.context(frameDecoderName);
    if (frameDecoder == null) {
        throw new IllegalArgumentException("WebSocketFrameDecoder not found: " + frameDecoderName);
    }
    ChannelHandler frameAggregator = new WebSocketFrameAggregator(DEFAULT_FRAME_MAX_SIZE);
    pipeline.addAfter(frameDecoder.name(), FRAME_AGGREGATOR_NAME, frameAggregator);
    return this;
}
Also used : WebSocketFrameAggregator(io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

WebSocketFrameAggregator (io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator)4 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 WebSocketServerHandshaker (io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker)2 WebSocketServerHandshakerFactory (io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory)2 Channel (io.netty.channel.Channel)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 WebSocket08FrameDecoder (io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder)1 WebSocket08FrameEncoder (io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder)1