Correct way to trigger WebSocket upgrade

Viewed 13

I am writing a application which will upgrade the HTTP connection to a WebSocket connection. I'm building the application over Netty. I'm using below code block to trigger the connection upgrade.

WebSocketServerHandshakerFactory wsFactory =
                new WebSocketServerHandshakerFactory(getWebSocketURL(req), null, true);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            handshaker.handshake(ctx.channel(), req);
        }
  1. When I try to upgrade the connection using above code from channelRead method of a InBoundHandler, Upgrade process works fine.
  2. When I try to trigger upgrade in read or write method of OutBoundHandler, I don't see anything on Wireshark. Feels like the request is just stuck somewhere and nothing is happening. (I have a use case to delay the upgrade).

Does WebSocket upgrade only works if triggered from InBoundHandler?

0 Answers
Related