in short, you have 3 main options:
-
open a thread per client, that spawns after you
accept(), and the run a loop in this context, that doesread() => .... => write() -
run a main loop that uses
select()on clients afteraccept()for each, and handle dispatching yourself. -
best option – use an async networking framework like
tornado,gevent,twistedor a few more to handle this transparently.
solved Python socket server: listening to multiple clients [closed]