django uwsgi websocket踩坑


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竟然也可以,感覺很詭異啊

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM