how can I make a server communicate with more than

2019-07-19 23:14发布

I am developing a server using python but the server can communicate with only one client at a time . Even if the server establish connection with more than one clients, it can't make conversation with all clients at the same time.

One client should wait until the started conversation end, which may last for several minutes. This problem would create Tremendous delay up on the client which hasn't started conversation.

So, how could I let my python server to communicate with more than one clients at the same time ?

Thank you in advance

2条回答
我想做一个坏孩纸
2楼-- · 2019-07-19 23:35

Your server needs to be multi threaded. Basically you should have the server listening on a specific port in a loop. Whenever a client request comes in, the server should spin off a new thread to handle the client at a different port and keep listening for the other incoming connection requests.

A nice answer here: python multithreaded server

查看更多
一纸荒年 Trace。
3楼-- · 2019-07-19 23:55

You may use Tornado. It is asynchronic multithreading web-server framework.

查看更多
登录 后发表回答