When I development some socket.io service in python environment by using python-socketio and gunicorn, I meet an issue here.
I am using Mac OS X and I am using python 3.7.
Environment setting
$ pip install python-socketio
$ pip install gunicorn
server-side code
app.py
import socketio
sio = socketio.Server()
app = socketio.WSGIApp(sio, static_files = {
'/': './socketio-client.html'
})
@sio.event
def connect(sid, environ):
print(sid, 'connected')
@sio.event
def disconnect(sid):
print(sid, 'disconnected')
client-side code
socketio-client.html
<html>
<head>
<title>Socket.IO Demo</title>
<script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script>
</head>
<body>
<h1>Socket.IO Demo</h1>
<script>
const sio = io();
sio.on('connect', () => {
console.log('connected');
});
sio.on('disconnect', () => {
console.log('disconnected');
});
</script>
</body>
</html>
Start program
I put the files in the same folder. And start it by following the command.
$ gunicorn --thread 50 app:app
I use the browser to open http://localhost:8000 and that works. Issue But there is an issue with the server
The WebSocket transport is not available, you must install a WebSocket server that is compatible with your async mode to enable it. See the documentation for details. (further occurrences of this error will be logged with level INFO)
I try to do
$ gunicorn --log-level INFO --thread 50 app:app
But I still cannot get helpful information from INFO log-level.
The code can keep going to run but the message shows me to install WebSocket server and I don't know which kind of package I need to install for this case of python-socketio or gunicorn.
What kind of package I missed to install?
It's my first time to use python-socketio and gunicorn.
What should I do next?
Thanks for your help.
It just needs to install more packages here.
$ pip install gevent-websocket
$ pip install eventlet
And then
$ gunicorn --thread 50 app:app
If the server-side need to active emit to client side, it will need this environment. Because this command $ gunicorn --thread 50 app:app
cannot support this situation.
The worked environment should be set by following.
$ pip install eventlet==0.30.2
$ gunicorn -k eventlet -w 1 app:app