Reputation: 11
http://flask-socketio.readthedocs.io/en/latest/
there are two description of how the emit
use.
Emit a SocketIO event.
This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This is a function that can only be called from a SocketIO event handler, as in obtains some information from the current client context. Example:
@socketio.on('my event') def handle_my_custom_event(json): emit('my response', {'data': 42})
The Engine.IO server configuration supports the following settings:
Emit a server generated SocketIO event.
This function emits a SocketIO event to one or more connected clients. A JSON blob can be attached to the event as payload. This function can be used outside of a SocketIO event context, so it is appropriate to use when the server is the originator of an event, outside of any client context, such as in a regular HTTP request handler or a background task. Example:
@app.route('/ping') def ping(): socketio.emit('ping event', {'data': 42}, namespace='/chat')
Upvotes: 1
Views: 765
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:
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