12

我正在尝试为 webSocket 连接编写服务器。我已经仔细阅读了规范(76,而不是 75)。我正在使用雷区作为浏览器。

当我尝试在浏览器中从 javascript 创建 WebSocket 时:

var ws = new WebSocket("ws://localhost:8766/hoho");

浏览器响应

“Firefox 无法与位于 ws://localhost:8766/hoho 的服务器建立连接。”

我的服务器正在获得一个有效的客户端握手请求,它发回响应然后繁荣。

我已经运行了可以通过服务器找到的每个握手示例,并且在每个实例中都完全匹配给定的响应。我非常有信心返回字节流是正确的。我不需要帮助调试我的代码,它正在按照我的意思做。我需要帮助调试我对握手协议的使用,因为当我给雷区我认为是正确的响应时,它会嘲笑我。

我的问题是:我该如何调试这个东西?我能想到两种可能。

  1. 有没有办法让雷区告诉我为什么它拒绝我的握手?

  2. 网络上是否有可用的公共 webSocket 服务器服务?如果有,我可以代理它,观察两个方向的字节流并找出我的不同之处。

有没有人对这些方向或任何其他想法有任何想法?

谢谢你的帮助。

4

3 回答 3

2

I'm in the process of debugging a similar situation, and the tool I'm relying on most is netcat, with some additional use of openssl. Shut down your websocket server and run nc -l 8766. That lets you record exactly what headers are being sent. Turn the websocket server back on and use nc 8766 to paste in those same headers and see the result. openssl s_client -connect localhost:443 will let you make the request with ssl, if that is in your mix.

From there, make sure the responses conform completely to the websocket handshake protocol. For instance, my problem right now is that my responses have Connection: close, which is no good.

于 2013-03-26T16:34:08.850 回答
2

关于第二种可能性。是的,那里有一个 websocket 服务器。jWebSocket 演示服务器位于http://jwebsocket.org/demos/chat/chat.htm

希望这可以帮助

补充:Echo 套接字服务器位于:http ://www.websocket.org/echo.html

于 2012-08-19T23:25:47.100 回答
1

这是我从http://www.websocket.org echo websocket 服务器制作的 jsfiddle,它适用于 Chrome,但不适用于 Firefox 6:http: //jsfiddle.net/awDLc/

它被调整为使用 MozWebSocket 而不是 WebSocket,但这可能还不够?

于 2011-08-24T22:03:49.533 回答