how can I make a server communicate with more than 1 client at the same time?

拥有回忆 提交于 2019-12-11 01:36:55

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/20172765/how-can-i-make-a-server-communicate-with-more-than-1-client-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!