I'm building a Flask application where I use Redis to receive data from a server, and then send that data to the frontend using Socket.IO. However, the emit() function is not sending the data to the frontend as expected.
Here is my Redis subscriber function:
def redis_subscriber():
pubsub = r.pubsub()
pubsub.subscribe('feed_channel')
print("Subscribed to feed_channel")
for message in pubsub.listen():
if message['type'] == 'message':
try:
data = message['data'].decode('utf-8')
# print(f"Emitting Redis data: {data}")
socketio.emit('new_data', json.dumps({"message": "Connected to Flask server"}))
except Exception as e:
print(f"Error processing message: {e}")
The Redis subscription is working fine, and I can confirm that messages are being received. However, the socketio.emit() call doesn't seem to send the data to the frontend.
Redis is properly set up and publishing messages to the feed_channel. The Socket.IO server is running and connected to the frontend.
What could be causing the emit() function to fail in sending the data via WebSocket?