多个客户端如何同时连接到服务器上的一个端口,比如 80? [英] How do multiple clients connect simultaneously to one port, say 80, on a server?

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

问题描述

我了解端口如何工作的基础知识.但是,我不明白的是多个客户端如何同时连接到端口 80.我知道每个客户端都有一个唯一的(用于他们的机器)端口.服务器是否从可用端口回复客户端,并简单地说明回复来自 80?这是如何工作的?

I understand the basics of how ports work. However, what I don't get is how multiple clients can simultaneously connect to say port 80. I know each client has a unique (for their machine) port. Does the server reply back from an available port to the client, and simply state the reply came from 80? How does this work?

推荐答案

首先,端口"只是一个数字.连接到端口"真正代表的只是一个数据包,该数据包在其目标端口"标头字段中指定了该编号.

First off, a "port" is just a number. All a "connection to a port" really represents is a packet which has that number specified in its "destination port" header field.

现在,您的问题有两个答案,一个针对有状态协议,一个针对无状态协议.

Now, there are two answers to your question, one for stateful protocols and one for stateless protocols.

对于无状态协议(即 UDP),没有问题,因为连接"不存在 - 多个人可以将数据包发送到同一个端口,并且他们的数据包将以任何顺序到达.没有人处于连接"状态.

For a stateless protocol (ie UDP), there is no problem because "connections" don't exist - multiple people can send packets to the same port, and their packets will arrive in whatever sequence. Nobody is ever in the "connected" state.

对于有状态协议(如 TCP),连接由一个 4 元组标识,该 4 元组由源和目标端口以及源和目标 IP 地址组成.因此,如果两台不同的机器连接到第三台机器上的同一个端口,就会有两个不同的连接,因为源 IP 不同.如果同一台机器(或 NAT 后面的两台机器或以其他方式共享相同 IP 地址的机器)两次连接到单个远程端,则连接按源端口(通常是随机的高编号端口)进行区分.

For a stateful protocol (like TCP), a connection is identified by a 4-tuple consisting of source and destination ports and source and destination IP addresses. So, if two different machines connect to the same port on a third machine, there are two distinct connections because the source IPs differ. If the same machine (or two behind NAT or otherwise sharing the same IP address) connects twice to a single remote end, the connections are differentiated by source port (which is generally a random high-numbered port).

简单地说,如果我从我的客户端连接到同一个 Web 服务器两次,从我的角度来看,这两个连接将具有不同的源端口和来自 Web 服务器的目标端口.因此没有歧义,即使两个连接具有相同的源和目标 IP 地址.

Simply, if I connect to the same web server twice from my client, the two connections will have different source ports from my perspective and destination ports from the web server's. So there is no ambiguity, even though both connections have the same source and destination IP addresses.

端口是一种多路传输 IP 地址的方式,以便不同的应用程序可以侦听相同的 IP 地址/协议对.除非应用程序定义自己的更高级别的协议,否则无法复用端口.如果使用相同协议的两个连接同时具有相同的源 IP 和目标 IP 以及相同的源端口和目标端口,则它们必须是同一连接.

Ports are a way to multiplex IP addresses so that different applications can listen on the same IP address/protocol pair. Unless an application defines its own higher-level protocol, there is no way to multiplex a port. If two connections using the same protocol simultaneously have identical source and destination IPs and identical source and destination ports, they must be the same connection.

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

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