fastapi-socketio icon indicating copy to clipboard operation
fastapi-socketio copied to clipboard

How to connect?

Open salvinoto opened this issue 2 years ago • 1 comments
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

salvinoto avatar Sep 02 '23 02:09 salvinoto

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())

leongkui avatar Oct 12 '23 14:10 leongkui