【发布时间】: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。
【问题讨论】:
-
能否给我示例源代码链接
-
如果我没记错的话,就是这个例子:github.com/netty/netty/blob/master/example/src/main/java/io/…
标签: java websocket netty handshake