现在在做一个项目,需要用到websocket,需要python去连接websocket,但是不知道怎么用python连接websocket,找了好久没找到,求各位大佬帮忙~~
现在在做一个项目,需要用到websocket,需要python去连接websocket,但是不知道怎么用python连接websocket,找了好久没找到,求各位大佬帮忙~~
感谢各位,百度了好久都找不到解决办法,楼上这位大神的应该可以用的,不过我看不太懂,感恩,上谷歌果然有收获,果断弃用百度
这是别人github上面的,可以用
# install ws4py
# pip install ws4py
# easy_install ws4py
from ws4py.client.threadedclient import WebSocketClient
class DummyClient(WebSocketClient):
def opened(self):
self.send("www.baidu.com")
def closed(self, code, reason=None):
print "Closed down", code, reason
def received_message(self, m):
print m
if __name__ == '__main__':
try:
ws = DummyClient('ws://10.222.138.163:1889/websocket', protocols=['chat'])
ws.connect()
ws.run_forever()
except KeyboardInterrupt:
ws.close()
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
flask 使用 gevent-websocket + gunicorn 部署
app.py
demo使用 gunicorn 启动 指定用 gevent-websocket
django 使用 Django-websocket
https://github.com/archever/p...