【问题标题】:io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: not a WebSoc ket handshake request: missing upgradeio.netty.handler.codec.http.websocketx.WebSocketHandshakeException:不是 WebSoc ket 握手请求:缺少升级
【发布时间】:2014-05-16 01:37:12
【问题描述】:

我使用Netty 编写了一个与Websockets 通信的服务器。

我经常收到这个错误:

io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: not a WebSoc
ket handshake request: missing upgrade
        at io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker00.ne
wHandshakeResponse(WebSocketServerHandshaker00.java:114)
        at io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker.hand
shake(WebSocketServerHandshaker.java:161)
        at io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker.hand
shake(WebSocketServerHandshaker.java:136)
        at chatserver.ChatServerHandler.handleHttpRequest(ChatServerHandler.java
:222)
   ....

ChatServerHandler 的第 222 行在这里:

private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception 
{
   ...

     WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(req), null, false);
        handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());// .sendUnsupportedVersionResponse(ctx.channel());
        } else {
            handshaker.handshake(ctx.channel(), req); // <<< this is line 222
        }

   ...
}

我能做些什么来解决它?

编辑:顺便说一句,我正在使用Netty 4.0.15 final final。

【问题讨论】:

标签: java websocket netty handshake


【解决方案1】:

我怀疑您显示的 sn-p 上方 handleHttpRequest 中的代码让一些非 websocket 请求漏掉了,也许是 favicon 请求?

【讨论】:

    猜你喜欢
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2013-04-04
    • 1970-01-01
    • 2018-11-26
    • 2019-04-02
    • 1970-01-01
    相关资源
    最近更新 更多