Background
I am trying to create a simple REST API using the Flask-RESTful extension. This API will be working primarily to manage the CRUD and auth
You just want to run socketio.run(app, port=5005)
and hit the REST API on port 5005.
The reason this works is because under the hood, Flask-SocketIO is running an evented webserver based on gevent (or with the 1.0 release, also eventlet) - this server handling the websocket requests directly (using the handlers you register via the socketio.on
decorator) and is passing on the non-websocket requests to Flask.
The reason your code wasn't working is because both app.run
and socketio.run
are blocking operations. Whichever one ran first was looping, waiting for connections, never allowing the second to kick off. If you really needed to run your websocket connections on a different port you'd need to spawn either the socketio or the app run
call on a different process.