Web服务器如何处理同一端口上的多个连接 [英] How does webserver handle multiple connections on the same port

查看:425
本文介绍了Web服务器如何处理同一端口上的多个连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TCP连接由[client IP address:outgoing port - server IP address:incoming port]定义. Web服务器在一个端口上侦听,但在同一端口上处理多个tcp连接-如何实现?一个连接是否以某种方式转移到其他传入端口以能够侦听新连接?

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?

推荐答案

即使服务器IP和服务器端口相同,客户端IP或客户端端口也不同.因此,从TCP的角度来看,这没有问题.

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.

如果需要更多详细信息,则服务器代码中有一个指定用于接受连接的套接字,该套接字将是侦听套接字,并且将绑定到服务器端口(并可选地绑定到IP).当客户端连接到该端口时,侦听套接字会接受它,并返回一个新的已连接套接字.

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.

这篇关于Web服务器如何处理同一端口上的多个连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆