我使用与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
决赛。
答案 0 :(得分:0)
我怀疑您所显示的代码段上方handleHttpRequest
中的代码是否允许某些非websocket请求漏掉,可能是favicon请求?