Skip to content Skip to sidebar Skip to footer

Python Socket Server: Listening To Multiple Clients

I must listen to incoming connections but at the same time I have to receive the messages from the already connected clients. However listen(1) makes the socket waiting so I can't

Solution 1:

in short, you have 3 main options:

  1. open a thread per client, that spawns after you accept(), and the run a loop in this context, that does read() => .... => write()

  2. run a main loop that uses select() on clients after accept() for each, and handle dispatching yourself.

  3. best option - use an async networking framework like tornado, gevent, twisted or a few more to handle this transparently.

Post a Comment for "Python Socket Server: Listening To Multiple Clients"