https://www.cnblogs.com/Xjng/p/4853080.html
上面的是參考內容,
我的環境如下,python2.7,django1.11,uwsgi2.0以上,niginx作為代理
安裝openssl: apt-get install libssl-dev, 安裝完這個uwsgi要重新裝
客戶端是用的websocket作為發送的,pip install websocket-client, 注意不是websocket這兩個import時候都是import websocket
uwsgi.ini中添加 http-websockets = true
重頭戲出現了,不能pip install uwsgi, 而是應該下源碼https://github.com/unbit/uwsgi, python setup.py install
def f(request): import uwsgi uwsgi.websocket_handshake() while True: msg = uwsgi.websocket_recv() uwsgi.websocket_send(msg)
#!/usr/bin/env python #import socket import websocket import time s = websocket.create_connection("ws://127.0.0.1:8080/xxx") print("Sending Hello, World...") s.send("Hello, World") print("sent") print("Receiving") a = 1 while 1: s.send("Hello, World{:0>9d}".format(a)) result = s.recv() print("Received '%s'" % result) time.sleep(1) a += 1 s.close()
網址被我改了,
終於跑通了,真是不容易,連續踩坑
今天在雲上部署websocket,直接pip install uwsgi竟然也可以,感覺很詭異啊