io.netty.handler.codec.http.websocketx.WebSocketHandshakeException:不是WebSoc ket握手请求:缺少升级

时间:2014-04-03 23:35:58

标签: java websocket netty handshake

我使用与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决赛。

1 个答案:

答案 0 :(得分:0)

我怀疑您所显示的代码段上方handleHttpRequest中的代码是否允许某些非websocket请求漏掉,可能是favicon请求?