javascript - Flask.SocketIO Fails to send data asynchronously to registered participants when async mode is "threading" -
edit: updated title nature of problem became more clear
i'm trying implement simple socket.io connection send broadcast events flask server javscript client. first server message reaches client, no more. on server side, keeps calling emit periodic data updates, client never receives messages after first one.
here javascript client (relevant lines extracted react app):
var io=require('socket.io-client') var socket = io.connect(); socket.on('connect', function() { console.log('connection established'); }); socket.on('message', function(data){ console.log('message received'); console.log(data); //only gets called first message sent server }
and flask server code:
from flask_socketio import socketio, emit app = flask(...) socketio = socketio(app, async_mode="eventlet") socketio.emit('message', "test data", broadcast=true) #update function called periodically json data #of form {"data": {...}} def update(data): data = json.dumps(data) socketio.emit('message', data, broadcast=true)
the client receives "test data" message, none of messages sent within update
function.
edit: find code in /usr/lib/python2.7/site-packages/socketio/base_manager.py
for sid in self.get_participants(namespace, room): if sid != skip_sid: if callback not none: id = self._generate_ack_id(sid, namespace, callback) else: id = none self.server._emit_internal(sid, event, data, namespace, id)
in debugger see sid value represents socket.io client, when server sends original "test data" , when sends subsequent updates. server still sees client participant, same id had begin with, , yet client doesn't receive of these subsequent updates. if emit 2 messages in row before update function emits events, client gets them. events emitted inside update function not received client.
i thought sort of scope issue, if server still sees client participant when events emitted inside update method, there doesn't seem scope problem. tried suggestion in 1 answer pass socketio
object update function, , got same behavior. can't understand why client not receive events because server sent them specific function, when execution context of function shows client still participant.
this simple example can conceive, , i'm doing same thing see in every example i've seen online. obviously, i'm missing something.
i think missed receive method on client side... please refer socket.io
socket.on('test', function (data) { console.log(data); });
Comments
Post a Comment