3

我用 Python 制作了自己的简单 WebSocket 服务器,但 Chrome 4.0.249.78 dev (36714) 在握手后总是断开连接。为了确保这不是我的代码,我使用在https://stackoverflow.com/questions/2153294?tab=newest#tab-top找到的 WebSocket 服务器对其进行测试并得到相同的结果(如下)。

listening...
connection!
GET / HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:1234
Origin: http://localhost


handshaken
got:
got:
Traceback (most recent call last):
  File "test.py", line 44, in <module>
    start_server()
  File "test.py", line 18, in start_server
    interact(csock, tick)
  File "test.py", line 40, in interact
    send_data(client, "clock ! tick%d" % (tick))
  File "test.py", line 25, in send_data
    return client.send(str)
socket.error: [Errno 10053] An established connection was aborted by the softwar
e in your host machine
Press any key to continue . . .

这是Javascript...

if ("WebSocket" in window) {
    var ws = new WebSocket("ws://localhost:1234");
    ws.onopen = function() {
        alert('opened');
        ws.send("test");
    }
    ws.onmessage = function (evt) {
        alert('hit');
        $('#game').html(evt.data);
    }
    ws.onclose = function () {
        $('#game').html('Lost Connection');
    }
} else {
    $('#game').html('No support');
}

是否有其他人遇到此问题,或者这似乎是域不匹配问题?

4

1 回答 1

2

我将 Chrome 升级到新版本(4.0.302.3 dev),现在我在控制台中收到了正确的 javascript 错误。这确实是域不匹配错误。

对于遇到同样问题的其他人,请确保先更新您的浏览器,然后检查您的网址。

于 2010-01-30T06:35:31.653 回答