How does webserver handle multiple connections on the same port [duplicate]

别来无恙 提交于 2019-12-24 13:47:13

问题


TCP connection is defined by [client IP address:outgoing port - server IP address:incoming port]. Web server listens on one port but handles multiple tcp connections on the same port - how is that achieved? Is one connection somehow transferred to other incoming port to be able to listen to new connection?


回答1:


Even if the server IP and server port are the same, the client IP or client port are different. So there is no problem, from the TCP point of view.

If you want more details, in the server code there is a socket destined to accept connections, that will be the listening socket and it will be bound to the server port (and optionally to the IP). When a client connects to this port the listening socket accepts it and a new connected socket is returned.

Even if all the server sockets use the same port, only one of them is actually listening, so there is no problem.



来源:https://stackoverflow.com/questions/33701350/how-does-webserver-handle-multiple-connections-on-the-same-port

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