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竟然也可以,感觉很诡异啊