django uwsgi websocket踩坑

https://www.cnblogs.com/Xjng/p/4853080.html

The above references,

My environment is as follows, python2.7, django1.11, uwsgi2.0 above, niginx as a proxy

Install openssl: apt-get install libssl-dev, after installing this uwsgi To replace

The client is used as websocket, pip install websocket-client sent websocket not pay attention at all times both import import websocket

Add http-websockets = true uwsgi.ini in

Main event there, can not pip install uwsgi, but should be under source 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()

 

I changed the URL,

Finally run through, it is not easy, continuous stepped pit

 

Guess you like

Origin www.cnblogs.com/mangmangbiluo/p/10931062.html