Skip to content

Multiple clients messaging the server simultaneously but not all receives the response #766

@bikash8gupta

Description

@bikash8gupta

Describe the bug
Whenever multiple clients try to send a message to the server simultaneously, the server only emits once to one of the clients and not to all clients. But it works when multiple clients come one after one and make a join call. The below is the sample code -

This is how I have configured socket.io with aiohttp.
Server Setup

if __name__ == '__main__':
    sio = socketio.AsyncServer(async_mode='aiohttp', cors_allowed_origins='*')
    sio.register_namespace(LiveCompetitionNamespace('/live_competition'))
    app = web.Application()
    sio.attach(app)
    web.run_app(app, path=args.path)

This is how i have declared the namespace -

BaseNamespace.py

class BaseNamespace(socketio.AsyncNamespace):
    async def on_connect(self, sid, environ):
        log.info("Connected")

    def on_disconnect(self, sid):
        log.info("Disconnected")

CompetitionNamespace.py

class LiveCompetitionNamespace(BaseNamespace):

    async def on_join(self, sid, msg):
        log.info("Join called by the user")
        room = 'competition_%s' % msg['competition_id']
        log.info("Putting the user in the room.")
        self.enter_room(sid, room)
        data = {} // This is the data from mongodb call
        log.info("Emitting the live_competition_joined to all users in the room except the new joiner")
        await self.emit('live_competition_joined', {'data': data}, room=room, skip_sid=sid)

Now when multiple clients after making a connection to the server, send a join message, the server only responds to some clients and not all. The server should emit to all clients except one making the join call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions