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:
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
,twisted
or a few more to handle this transparently.
Post a Comment for "Python Socket Server: Listening To Multiple Clients"