Emitting event from socketIo python
<p>I'm stuck in development of socket.io with Python. I'm using this <a href="http://python-socketio.readthedocs.io/en/latest/" rel="nofollow">lib</a> </p>

<p>I got a chat app running by using <a href="https://github.com/sreejesh79/android-socket.io-demo" rel="nofollow">this</a> android part and with the lib sample. I want to trigger an event from the server side from a separate file. Here's my code.</p>

<pre><code>import socketio
import eventlet
from flask import Flask, render_template

sio = socketio.Server(logger=True, async_handlers= True)
app = Flask(__name__)

eventlet.monkey_patch()

@sio.on('connect', namespace='/d')
def connect(sid, environ):
   print('connect ', sid)
   pass

@sio.on('messaget', namespace='/d')
def messaget(sid, data):
    print('message ', data)
    # sio.emit('messaget', data, namespace='/d')
    # sendmsg("YO YO")

@sio.on('disconnect', namespace='/d')
def disconnect(sid):
   print('disconnect ', sid)

def start_socket(app):
   # wrap Flask application with socketio's middleware
   app = socketio.Middleware(sio, app)
   eventlet.wsgi.server(eventlet.listen(('', 8000)), app)

def sendmsg(data):
    my_data= { 'text': data };
    sio.emit('messaget', my_data, namespace='/d')

start_socket(app)
</code></pre>

<p>I'm calling <code>sendmsg("dipen")</code> from my another python file. I'm getting a log <strong>emitting event "messaget" to all [/d]</strong> but android app is not getting any messages. And it work's if event is emitting from the Android app. I tried with the NodeJs code and it worked for the NodeJs code so I'm pretty sure that something is wrong in my Python code. Hope that someone could save me from this. </p>

<p>Send a message from Android client. Does your Python code get it? If not, check if you have connected to the same namespace.</p>

python node.js socket.io chat real-time