我在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');
}
是否有其他人遇到此问题或是否出现域名不匹配问题?
答案 0 :(得分:2)
我将Chrome升级到新版本(4.0.302.3 dev),现在我在控制台中收到正确的javascript错误。这确实是一个域名不匹配错误。
对于遇到同样问题的其他人,请务必先更新浏览器,然后检查您的网址。