lmx_xml
lmx_xml

Reputation: 11

what's the relationship between flask-socketio and Engine.IO?

http://flask-socketio.readthedocs.io/en/latest/
there are two description of how the emit use.


flask_socketio version

flask_socketio.emit(event, *args, **kwargs)


    @socketio.on('my event')
    def handle_my_custom_event(json):
        emit('my response', {'data': 42})

Parameters:


Engine.io version

The Engine.IO server configuration supports the following settings:

emit(event, *args, **kwargs)


    @app.route('/ping')
    def ping():
        socketio.emit('ping event', {'data': 42}, namespace='/chat')

Parameters:

Upvotes: 1

Views: 765

Answers (1)

Miguel Grinberg
Miguel Grinberg

Reputation: 67479

I'm not sure from where you deduced that the second function is an "Engine.IO version". That is wrong. The two things that you are comparing are both in the Socket.IO package:

  • flask_socketio.emit()
  • flask_socketio.SocketIO.emit()

The difference between these two is merely that the former is a "context-aware" function, while the latter is not. Both send a Socket.IO event, but with the first one a default recipient and namespace are extracted from the Flask request context, so you can only use it when a context is available. For the second one you need to provide the recipient and the namespace yourself.

I'm not sure why you introduced Engine.IO in this discussion. This is a lower level communication protocol on top of which Socket.IO is built. It is actually much simpler than Socket.IO, and can only send a message from the server to a single client, or from a client to the server. No support for namespaces, rooms, broadcasts, etc.

Upvotes: 1

Related Questions