Search in sources :

Example 21 with PingWebSocketFrame

use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project reactor-netty by reactor.

the class WebsocketServerOperations method onInboundNext.

@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void onInboundNext(ChannelHandlerContext ctx, Object frame) {
    if (frame instanceof CloseWebSocketFrame && ((CloseWebSocketFrame) frame).isFinalFragment()) {
        if (log.isDebugEnabled()) {
            log.debug(format(channel(), "CloseWebSocketFrame detected. Closing Websocket"));
        }
        CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(true, ((CloseWebSocketFrame) frame).rsv(), ((CloseWebSocketFrame) frame).content());
        if (closeFrame.statusCode() != -1) {
            // terminate() will invoke onInboundComplete()
            sendCloseNow(closeFrame, f -> terminate());
        } else {
            // terminate() will invoke onInboundComplete()
            sendCloseNow(closeFrame, WebSocketCloseStatus.EMPTY, f -> terminate());
        }
        return;
    }
    if (!this.proxyPing && frame instanceof PingWebSocketFrame) {
        // "FutureReturnValueIgnored" this is deliberate
        ctx.writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) frame).content()));
        ctx.read();
        return;
    }
    if (frame != LastHttpContent.EMPTY_LAST_CONTENT) {
        super.onInboundNext(ctx, frame);
    }
}
Also used : CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) PingWebSocketFrame(io.netty.handler.codec.http.websocketx.PingWebSocketFrame)

Aggregations

PingWebSocketFrame (io.netty.handler.codec.http.websocketx.PingWebSocketFrame)21 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)18 PongWebSocketFrame (io.netty.handler.codec.http.websocketx.PongWebSocketFrame)17 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)14 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)7 URI (java.net.URI)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Test (org.junit.jupiter.api.Test)6 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)5 BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)5 WebSocketClientHandshakeException (io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException)5 WebSocketHandshakeException (io.netty.handler.codec.http.websocketx.WebSocketHandshakeException)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Unpooled (io.netty.buffer.Unpooled)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 CorruptedFrameException (io.netty.handler.codec.CorruptedFrameException)4 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)4 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)4 ClientCookieDecoder (io.netty.handler.codec.http.cookie.ClientCookieDecoder)4 ClientCookieEncoder (io.netty.handler.codec.http.cookie.ClientCookieEncoder)4