我用与Websockets
通信的Netty
编写了一个服务器。
我经常收到此错误:
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
决赛。
我怀疑您显示的代码片段上方handleHttpRequest
中的代码让一些非 websocket 请求溜走,也许是图标请求?