发送消息时未调用 WebSocket onmessage()
我使用 autobahn 0.4.10 (https://github.com/oberstet/Autobahn) 作为 WebSocket 服务器将消息发送到 Google Chrome 扩展程序。我可以使用 WebSocket()
打开和关闭连接,但是当我调用 autobahn.websocket.WebSocketServerProtocol.sendMessage()
时,消息似乎已发送,但实际上并未发送传送直到连接关闭。
WebSocketServerProtocol 的 sendMessage()
(派生自 WebSocketProtocol)的 api 可以在这里找到:http://www.tavendo.de/autobahn/doc/python/websocketprotocol.html#autobahn.websocket.WebSocketProtocol
有没有人遇到过这个问题?
我在客户端的代码是(js):
ws = new WebSocket('ws://localhost:4444');
ws.onmessage = function(event) {
console.log('hii');
}
在服务器上(python)...
#json is a string object
def sendEvent(self, json):
print 'to', self.peerstr
self.sendMessage(json, sync=True)
Autobahn 和我的 Chrome 版本(17.0.963.46)都出现(从我从标题和文档中得到的内容) )使用 WebSocket 草案协议版本 13。
I'm using autobahn 0.4.10 (https://github.com/oberstet/Autobahn) as a WebSocket server to send messages to a Google Chrome Extension. I am able to open and close connections using WebSocket()
, but when I call autobahn.websocket.WebSocketServerProtocol.sendMessage()
the message appears to be sent but isn't delivered until the connection is closed.
The api for WebSocketServerProtocol's sendMessage()
(derived from WebSocketProtocol) can be found here: http://www.tavendo.de/autobahn/doc/python/websocketprotocol.html#autobahn.websocket.WebSocketProtocol
Has anyone experienced this problem before?
The code I have been on the client side is (js):
ws = new WebSocket('ws://localhost:4444');
ws.onmessage = function(event) {
console.log('hii');
}
And on the server (python)...
#json is a string object
def sendEvent(self, json):
print 'to', self.peerstr
self.sendMessage(json, sync=True)
Both Autobahn and my version of Chrome (17.0.963.46) appear (from what I've gotten out of the headers and docs) to use version 13 of the WebSocket draft protocol.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,这是一个线程问题,一些线程阻塞了扭曲的反应器。
看:
http://groups.google.com/group/autobahnws/browse_thread/thread/ 6bf0c43ec169efc3#
http://twistedmatrix.com/documents/current/core/howto/threading.html
Turns out this was a threading problem with some threads block the twisted reactor.
See:
http://groups.google.com/group/autobahnws/browse_thread/thread/6bf0c43ec169efc3#
http://twistedmatrix.com/documents/current/core/howto/threading.html
Autobahn 可与 Chrome 配合使用(已测试至 v19 .. Canary)。
您可以尝试
https://github.com/oberstet/Autobahn /blob/master/demo/broadcast/broadcast_server.py
演示看看您是否遇到一般问题?
如果运行,请将您的扩展程序定向到该演示服务器..它将每秒向您发送 1 个刻度。
您还可以通过将工厂行更改为如下代码来启用调试输出
https://github.com/oberstet/Autobahn/blob/master/demo/echo/echo_server_with_logging.py#L50
还有 2 个注释:
您不需要sync = True选项(它确实是一个高级选项..主要与Autobahn WS测试套件一起使用)
您可能想加入 http://groups.google.com/group/autobahnws ..更快地获得答案..我在这里偶然发现了您的问题
披露:我是《Autobahn》的作者,为 Tavendo 工作。
Autobahn works with Chrome (tested up to v19 .. Canary).
Could you try the
https://github.com/oberstet/Autobahn/blob/master/demo/broadcast/broadcast_server.py
demo to see if you have a general issue?
If that runs, direct your extension to that demo server .. it'll send you 1 tick per sec.
You can also enable debug output by changing the factory line to code like this
https://github.com/oberstet/Autobahn/blob/master/demo/echo/echo_server_with_logging.py#L50
2 more notes:
you don't need the sync = True option (it's really an advanced option .. mostly used with the Autobahn WS testsuite)
you might wanna join http://groups.google.com/group/autobahnws .. get answers more quickly .. I discovered your Q only by accident here
Disclosure: I am author of Autobahn and work for Tavendo.