websocket握手连接失败

xubenhai

在服务器上部署好代码:
客户端(js建立的websocket连接)报错如下

   WebSocket connection to 'ws://chat.migucloud.com:8282/' failed: Error during WebSocket handshake: Invalid status line

用tcpdump命令进行抓包,数据包如下:
客户端发送的握手请求:

GET / HTTP/1.1
Host: chat.migucloud.com:8282
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://ws.migucloud.com
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8
Sec-WebSocket-Key: IurTkvmv2xhCl6kgdq7h0g==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

workerman会把握手的头部文件当做消息来处理 onMessage(Gateway)会把头文件当做message来处理
服务器就再也没有返回握手应答

我在另外一台阿里云的机子上部署代码(php环境一致),可以握手成功 数据包如下:

 GET / HTTP/1.1
Host: chat.87v5.com:8282
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://ws.migucloud.com
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8
Sec-WebSocket-Key: xdtSMupKZ9//1unMpbeASA==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

返回的握手应答:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Sec-WebSocket-Version: 13
Connection: Upgrade
Server: workerman/3.3.6
Sec-WebSocket-Accept: GsXZKr8BQoozzMAZOXYUQn/Xp10=

能成功的建立起websocket连接

求大大解决,如有描述不清楚的地方请大大追问

22057 1 0
1个回答

walkor 打赏

服务端协议要和客户端协议一致才能通讯。

客户端是websocket协议,服务端也要设置成websocket协议

把start_gateway.php 中new Gateway('tcp://0.0.0.0:8282'); 改成 new Gateway('websocket://0.0.0.0:8282');

年代过于久远,无法发表回答
×
🔝