I currently have a python socket.io server and client. However, I want to trigger a emit event from another file. The function sendMsg runs and prints out sending, however, my client never receives any message.
Server:
from aiohttp import web
import socketio
import threading
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
async def sendMsg(msg):
print("sending")
await sio.emit("response",msg)
@sio.event
def connect(sid, environ):
print(\'connect \', sid)
sio.emit("response","ready")
@sio.event
def disconnect(sid):
print(\'disconnect \', sid)
print("Client is disconnected, please restart server/client connection")
@sio.on(\'message\')
async def print_message(sid, message):
print("Socket ID: " , sid)
print(message)
await sio.emit("response","test")
if __name__ == \'__main__\':
print("starting server")
web.run_app(app)
Client:
import time
import socketio
sio = socketio.Client()
@sio.event
def connect():
print(\'connected to server\')
sio.emit("message","connected")
@sio.event
def response(data):
print(\'res rec\', data)
@sio.on("letter")
def letter(data):
print(data)
if __name__ == \'__main__\':
sio.connect(\'http://localhost:8080\')
sio.wait()
I don\'t know if this is a server issue or client issue, any help would be appreciated.