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

查看:353
本文介绍了多个客户端如何同时连接到服务器上的一个端口(例如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元组标识,包括源端口和目标端口,源和目标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以及相同的源和目标端口,则它们必须是相同的连接。

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 have identical source and destination IPs and identical source and destination ports, they must be the same connection.

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

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