久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

請教一下,python怎么連接websocket

瀏覽:145日期:2022-07-13 15:09:37

問題描述

現在在做一個項目,需要用到websocket,需要python去連接websocket,但是不知道怎么用python連接websocket,找了好久沒找到,求各位大佬幫忙~~

問題解答

回答1:flask 使用 gevent-websocket + gunicorn 部署

pip3 install gevent-websocketpip3 install gunicorn

app.py demo

from geventwebsocket.handler import WebSocketHandlerfrom gevent.pywsgi import WSGIServerapp = Flask(__name__)@app.route(’/echo/’)def echo(): if request.environ.get(’wsgi.websocket’):ws = request.environ[’wsgi.websocket’]while True: msg = ws.receive() ws.send(msg)if __name__ == ’__main__’: http_server = WSGIServer((’’, 5000), app, handler_class=WebSocketHandler) http_server.serve_forever()

使用 gunicorn 啟動 指定用 gevent-websocket

gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker app:appdjango 使用 Django-websocket

https://github.com/archever/p...

回答2:

感謝各位,百度了好久都找不到解決辦法,樓上這位大神的應該可以用的,不過我看不太懂,感恩,上谷歌果然有收獲,果斷棄用百度

這是別人github上面的,可以用

# install ws4py# pip install ws4py# easy_install ws4pyfrom ws4py.client.threadedclient import WebSocketClientclass 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 mif __name__ == ’__main__’: try:ws = DummyClient(’ws://10.222.138.163:1889/websocket’, protocols=[’chat’])ws.connect()ws.run_forever() except KeyboardInterrupt:ws.close()回答3:

建議使用tornado,它支持websocket,知乎后端就是使用tornado構建的

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 狠狠干美女 | 国产精品不卡视频 | 日韩在线 | 中文字幕在线观看的电影 | 日韩精品一区二区三区 | 国产精品久久久久久久久免费桃花 | 中文字幕一区二区三区四区 | 精品一二三区 | 欧美成人精品一区二区男人看 | www.蜜桃av| 欧美全黄 | 在线观看亚洲一区二区三区 | av大片在线观看 | 天天干夜夜爽 | 中文字幕国产日韩 | 四虎网址| 99久久婷婷国产综合亚洲 | 日本在线免费 | 精品一区免费 | 午夜欧美 | 精品亚洲永久免费精品 | 欧美精三区欧美精三区 | 国产精品久久久久久久久污网站 | 久草在线 | 久久se精品一区精品二区 | 国产精品乱码一二三区的特点 | 北条麻妃国产九九九精品小说 | 色吧一区 | 久久亚洲一区 | 国产精品久久久久久久竹霞 | 91久久爽久久爽爽久久片 | 国产免费一区 | 亚洲嫩草 | 成人福利av | 亚洲欧美视频 | www.中文字幕在线 | 免费成人精品 | 拍真实国产伦偷精品 | 久草视频在线播放 | 中文字幕66页 | 国产一区二区影院 |