pyropy / fastapi-socketio

Easily integrate socket.io with your FastAPI app 🚀
Apache License 2.0
328 stars 31 forks source link

How to connect? #45

Open salvinoto opened 11 months ago

salvinoto commented 11 months ago

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

leongkui commented 10 months ago

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