heroku-python / flask-sockets

[DEPRECATED] Alternative: https://github.com/miguelgrinberg/flask-sock
MIT License
1.74k stars 167 forks source link

How to deploy flash sockets in uwsgi CentOS ? #74

Open ShawnChen-dev opened 4 years ago

ShawnChen-dev commented 4 years ago

Receive message interface exception information as follows:

environment = environ['wsgi.websocket'] KeyError: 'wsgi.websocket'

colin-riddell commented 4 years ago

Hi @ShawnChen-dev - you really need to give a lot more explanation about what you're trying to do specifically. What you're using, what code you've ran etc before anyone can help you.

From the very little we can see, it looks like perhaps the environ dictionary doesn't have the key "wsgi.websocket" as a literal. Though without knowing more it's hard to say what's going on.

ShawnChen-dev commented 4 years ago

Thank you for the reminder. I did it : `import json from flask import Flask from flask_sockets import Sockets

app = Flask(name) sockets = Sockets(app)

@sockets.route('/echo') def echo_socket(ws): while not ws.closed: message = ws.receive() if message is not None: ws.send(json.dumps({'output': message['output']}))

@app.route('/') def hello(): return 'Hello World!'

if name == "main": from gevent import pywsgi from geventwebsocket.handler import WebSocketHandler

server = pywsgi.WSGIServer(('0.0.0.0', 9017), app, handler_class=WebSocketHandler)
server.serve_forever()

`

Deploy to centos7 and run this file directly. Both interfaces are normal, but running through uwsgi(uwsgi --ini flask_uwsgi.ini), HTTP interface is normal, and WS interface throws an exception environment = environment [' wsgi.websocket ] KeyError: ' wsgi.websocket '

uwsgi config: [uwsgi] uid=root gid=root http-socket = 0.0.0.0:9024 chdir=/root/test-scc/scc_service master=true vhost = True workers = 2 enable-threads = True wsgi-file= run.py callable = app module=run:app logto=/var/error.log python-autoreload=1 touch-chain-reload = true uwsgi_read_timeout = 600 limit-as = 6048 processes=4 gevent= 100 This problem has bothered me for a long time. I hope my experienced friends can help me!