发送消息时未调用WebSocket onmessage()
WebSocket onmessage() not being called when messages are sent
我使用的是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版。
原来这是一个线程问题,一些线程阻塞了扭曲的反应器。
请参阅: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/broadcastrongerver.py
演示,看看你是否有一个普遍的问题?
如果运行,请将您的扩展指向该演示服务器。。它会每秒向你发送1次。
您还可以通过将工厂行更改为类似的代码来启用调试输出
https://github.com/oberstet/Autobahn/blob/master/demo/echo/echo_server_with_logging.py#L50
另外2条注释:
-
您不需要sync=True选项(它实际上是一个高级选项…主要用于高速公路WS测试套件)
-
你可能想加入http://groups.google.com/group/autobahnws。。更快地得到答案。。我在这里偶然发现了你的Q
披露:我是《高速公路》的作者,为塔文多工作。
- chrome在WebSocket握手期间获取新错误
- ReactJS和SpringDataRest缓存问题可能与websocket有关
- Node.js上的WebSocket,并在所有连接的客户端之间共享消息
- Tomcat websocket is not working
- WebSocket握手:意外的响应代码:404
- Websocket赢得't打开连接
- Javascript connect to websocket
- 服务器端事件+客户端事件与Websocket
- 通过html5/websocket通过wifi传输文件
- 为什么我的WebSocket客户端总是在发送消息后重新加载
- WebSocket onmessage not firing
- JavaScript和Java WebSocket SSL连接错误
- WebSocket.onmessage没有'不起作用
- WebSocket onMessage 在 AJAX 请求期间未触发
- WebSocket:onMessage() 仅在服务器关闭连接时触发
- 发送消息时未调用WebSocket onmessage()
- websocket客户端中的onmessage事件未被激发
- 添加到WebSocket.onmessage()中,就像jQuery添加到事件中一样
- C#创建websocket-onmessage函数没有'不起作用
- 获取OnMessage() websocket的值