fastapi-socketio
fastapi-socketio copied to clipboard
How to connect?
trafficstars
Do I use the same port as my FastAPI server? I have it running on port 8000, this is what my URL looks like when I try to connect
http://localhost:8000/ws/socket.io/
Is that correct, Im using the default setting.
Thanks
This is a python client example:
import asyncio
import socketio
debug=False
sio = socketio.AsyncSimpleClient(
logger=debug,
engineio_logger=debug,
)
async def main():
await sio.connect(
'http://localhost:8000',
socketio_path='/ws/socket.io',
)
await sio.emit('join', {'room': 'aaaa'})
event = await sio.receive()
print('event = {}'.format(event))
await sio.emit('leave', {'room': 'aaaa'})
event = await sio.receive()
print('event = {}'.format(event))
await sio.disconnect()
if __name__ == '__main__':
asyncio.run(main())