Websocket握手无法建立连接

时间:2013-03-07 02:30:51

标签: websocket

在wensocket服务器上获取的请求是:

Upgrade: websocket
Connection: Upgrade
Host: 10.1.5.20:5555
Origin: http://localhost:8080
Sec-WebSocket-Protocol: sip
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: T3jkd1s0pRceQbgdTLoaiQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame

我试图回复握手的回复是:

HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: http://localhost:8080
Sec-WebSocket-Location: ws://10.1.5.20:5555/

但我收到的错误是:

**Exception in thread "main" java.io.IOException: Handshake failed
    at websocket4j.AbstractWebSocket.<init>(AbstractWebSocket.java:123)
    at websocket4j.server.WebSocket.<init>(WebSocket.java:73)
    at websocket4j.server.WebServerSocket.accept(WebServerSocket.java:119)
    at websocket4j.examples.EchoServer.main(EchoServer.java:51)
Caused by: java.io.IOException: End of stream
    at websocket4j.AbstractWebSocket.readBytes(AbstractWebSocket.java:230)
    at websocket4j.server.WebSocket.handshake(WebSocket.java:203)
    at websocket4j.AbstractWebSocket$HandshakeRunner.run(AbstractWebSocket.java:79)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)**

1 个答案:

答案 0 :(得分:0)

你不应该用钥匙回答吗? 尝试在您的回复中添加Sec-WebSocket-Accept:sha1(Sec-WebSocket-Key +魔术字符串)