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

 

转载于:https://www.cnblogs.com/mangmangbiluo/p/10931062.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值