0

在 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)**
4

1 回答 1

0

你不应该用钥匙回应吗?尝试在您的响应中添加 Sec-WebSocket-Accept: sha1(Sec-WebSocket-Key + magic string )

于 2013-03-22T09:22:38.130 回答