国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

請(qǐng)教一下,python怎麼連接websocket
phpcn_u1582
phpcn_u1582 2017-05-18 10:54:01
0
3
1024

現(xiàn)在在做一個(gè)項(xiàng)目,需要用到websocket,需要python去連接websocket,但是不知道怎麼用python連接websocket,找了好久沒(méi)找到,求各位大佬幫忙~~

#
phpcn_u1582
phpcn_u1582

全部回覆(3)
我想大聲告訴你

flask 使用 gevent-websocket + gunicorn 部署

pip3 install gevent-websocket
pip3 install gunicorn

app.py demo

from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer

app = 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 啟動(dòng) 指定用 gevent-websocket

gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker app:app

django 使用 Django-websocket

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

為情所困

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

這是別人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()
劉奇

建議使用tornado,它支援websocket,知乎後端就是使用tornado建構(gòu)的

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板