Using eventlet to control socketio in Flask

I'm trying to set up a small server to handle HTTP requests and sockets - I don't have much experience configuring servers, but right now apache2 works fine with http. However, socketio transactions continue to fail with error code 400 ("bad request"), and I see some strange errors in the server logs. Sometimes I see an engineio error and the server responds with a “bad request” and code 400, but it always tells me that the eventlet server should be running:

[Mon Jan 11 19:02:54.068282 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473]     return ws(environ, start_response)
[Mon Jan 11 19:02:54.068305 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473]   File "/var/www/projectENV/lib/python2.7/site-packages/engineio/async_eventlet.py", line 10, in __call__
[Mon Jan 11 19:02:54.068342 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473]     raise RuntimeError('You need to use the eventlet server.')
[Mon Jan 11 19:02:54.068380 2016] [:error] [pid 4908:tid 140274923673344] [client 100.96.180.39:53473] RuntimeError: You need to use the eventlet server. See the Deployment section of the documentation for more information.
[Mon Jan 11 19:02:54.253124 2016] [:error] [pid 4909:tid 140274940458752] WARNING:engineio:Invalid session cde3f9aadbee4794bf9d7bb98d0b396e

My server code is pretty simple:

 from flask import Flask
 import flaskext.couchdb
 from flask.ext.socketio import SocketIO

 # for socketio
 import eventlet
 eventlet.monkey_patch()

 # creation of server & db objects
 app = Flask(__name__)

 # socketio initialization
 socketio =  SocketIO(app, async_mode='eventlet')

 # import views once site properties are set
 from app import views

 if __name__== "__main__":
     socketio.run(app, debug=True)

And my client code written in python uses the client socket library directly from the docs:

from socketIO_client import SocketIO, LoggingNamespace
with SocketIO(SERVER_URL, 80, LoggingNamespace) as socketIO:
    socketIO.emit('aaa')
    socketIO.wait(seconds=1)

Is socketio.run(app)to start the event server? Why does the server reject an invalid request (sometimes)?

+4
1

WSGI , -. Flask-SocketIO, - WSGI , WSGI WebSocket, WSGI .

Flask-SocketIO -, WebSocket. , eventlet, , - eventlet.

, , , , , - Apache ( mod_wsgi?). - , -, -.

.run(app) ?

, socketio.run(app), - . , apache. Eventlet -, apache -, -, WSGI. apache WebSocket.

Flask-SocketIO .

+7

Source: https://habr.com/ru/post/1623856/