websocket
1.实现方案一:
django + dwebsocket + gunicorn +nginx
pip install dwebsocket
部分代码
from dwebsocket import require_websocket @require_websocket def ws(request): if not request.is_websocket(): # 判断是不是websocket连接 pass else: 多线程 while request.websocket.has_messages: msg= request.websocket.wait() if msg: 。。。 接受方法 。。。 req.websocket.send(data)
设置 gunicorn 的timeout 解决30秒退出
nohub gunicorn -w 6 -b 127.0.0.1:8080 --timeout 3600&
nginx.conf
server{ # the port your site will be served on listen 80; # the domain name it will serve for #server_name www.scloud.cn; # substitute your machine‘s IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /opt/soft/pro_name/media; # your Django project‘s media files - amend as required } location /static { alias /opt/soft/pro_name/static; # your Django project‘s static files - amend as required } location / { # 反向代理透传客户端ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:8080; } #websocket setting location /app/websocket_url { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 600; proxy_send_timeout 120; proxy_read_timeout 600; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
2.实现方案二:
django +uwsgi + nginx
import uwsgi
uwsgi.websocket_recv_nb()
会爆出异常 no Pone until 30 seconds
解决方案: 1.修改uwsgi 源码 : 在初始化中将默认的30秒改大,或者注释掉check_ping_pong 方法
2.误打误撞不知道修改了什么,解决了,但是很遗憾,我忘记了自己做了什么
暂时还没弄懂为什么发了ping,没有响应pong
webssh
xterm.js
默认是utf-8 ,最小容器是没有按照vim的,使用vim注意解决编码问题,以及width and height,编码有误会出现闪退问题。 宽和高设置错误,会不显示全屏
版权声明:本文为博主原创文章,未经博主允许不得转载。