0
我寫了一個服務器,使用Netty
與Websockets
通信。io.netty.handler.codec.http.websocketx.WebSocketHandshakeException:不是WebSoc的握手請求:缺少升級
我經常得到這個錯誤:
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
最後的方式。
你能給我舉個例子源代碼鏈接 –
如果我沒有記錯的話,從這個例子來看:https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example /http/websocketx/server/WebSocketServerHandler.java – spacecoyote