应用程序如何使用端口 80/HTTP 而不与浏览器发生冲突?
如果我理解正确的话,应用程序有时会使用 HTTP 来发送消息,因为使用其他端口可能会导致防火墙问题。但如何在不与网络浏览器等其他应用程序发生冲突的情况下工作呢?事实上多个浏览器同时运行如何不冲突呢?他们都监视端口并收到通知吗...您可以通过这种方式共享端口吗?
我觉得这是一个愚蠢的问题,但我以前从未想过,在其他情况下,当两个应用程序配置为使用同一端口时,我会遇到问题。
If I understand right, applications sometimes use HTTP to send messages, since using other ports is liable to cause firewall problems. But how does that work without conflicting with other applications such as web-browsers? In fact how do multiple browsers running at once not conflict? Do they all monitor the port and get notified... can you share a port in this way?
I have a feeling this is a dumb question, but not something I ever thought of before, and in other cases I've seen problems when 2 apps are configured to use the same port.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有 2 个端口:源端口(浏览器)和目标端口(服务器)。浏览器向操作系统请求可用的源端口(假设它收到 33123),然后与目标端口(通常为 80/HTTP、443)建立套接字连接/HTTPS)。
当 Web 服务器收到应答时,它会发送一个响应,该响应的源端口为 80,目标端口为 33123。
因此,如果您有 2 个浏览器同时访问 stackoverflow.com,您将看到如下内容:
There are 2 ports: a source port (browser) and a destination port (server). The browser asks the OS for an available source port (let's say it receives 33123) then makes a socket connection to the destination port (usually 80/HTTP, 443/HTTPS).
When the web server receives the answer, it sends a response that has 80 as source port and 33123 as destination port.
So if you have 2 browsers concurrently accessing stackoverflow.com, you'd have something like this:
传出 HTTP 请求不会发生在端口 80 上。当应用程序请求套接字时,它通常会随机接收一个套接字。这是源端口。
端口 80 用于提供 HTTP 内容(由服务器而不是客户端)。这是目标端口。
每个浏览器使用不同的 Source 来生成请求。这样,数据包就会返回到正确的应用程序。
Outgoing HTTP requests don't happen on port 80. When an application requests a socket, it usually receives one at random. This is the Source port.
Port 80 is for serving HTTP content (by the server, not the client). This is the Destination port.
Each browser uses a different Source to generate requests. That way, the packets make it back to the correct application.
它是标识连接的五元组(IP协议、本地IP地址、本地端口、远程IP地址、远程端口)。多个浏览器(或者实际上同时加载多个页面的单个浏览器)将各自使用目标端口 80,但本地端口(由操作系统分配)在每种情况下都是不同的。因此不存在冲突。
It is the 5-tuple of (IP protocol, local IP address, local port, remote IP address, remote port) that identifies a connection. Multiple browsers (or in fact a single browser loading multiple pages simultaneously) will each use destination port 80, but the local port (which is allocated by the O/S) is distinct in each case. Therefore there is no conflict.
客户端通常选择 1024 到 65535 之间的端口。
这取决于操作系统如何处理这个问题。我认为 Windows 客户端会为每个新连接增加值,Unix 客户端会选择一个随机端口号。
某些服务依赖于静态客户端端口,例如 NTP (123 UDP)
Clients usually pick a port between 1024 and 65535.
It depends on the operating system how to handle this. I think Windows Clients increment the value for each new connection, Unix Clients pick a random port no.
Some services rely on a static client port like NTP (123 UDP)
浏览器是一种客户端应用程序,您可以使用它来查看通常位于不同计算机上的网络服务器上的内容。
Web 服务器是监听端口 80 的服务器,而不是客户端上的浏览器。
A browser is a client application that you use in order to see content on a web server which is usually on a different machine.
The web server is the one listening on port 80, not the browser on the client.
您需要小心区分“侦听端口 80”和“连接到端口 80”。
当您说“应用程序有时使用 HTTP 发送消息,因为使用其他端口容易导致防火墙问题”时,您实际上的意思是“应用程序有时向端口 80 发送消息”。
服务器正在侦听端口 80,并且可以接受该端口上的多个连接。
You need to be careful in making the distinction between "listening on port 80" and "connecting to port 80".
When you say "applications sometimes use HTTP to send messages, since using other ports is liable to cause firewall problems", you actually mean "applications sometimes send messages to port 80".
The server is listening on port 80, and can accept multiple connections on that port.
您在这里谈论的端口 80 是服务器上的远程端口,本地浏览器为每个建立的连接打开高端口。
每个连接的两端都有端口号,一个称为本地端口,另一个称为远程端口。
防火墙将允许流量流向浏览器的高端口,因为它知道已从您的计算机建立了连接。
Port 80 you're talking about here is the remote port on the server, locally browser opens high port for each connection established.
Each connection has port numbers on both ends, one is called local port, other remote port.
Firewall will allow traffic to high port for browser, because it knows that connection has been established from you computer.