应用程序如何使用端口 80/HTTP 而不与浏览器发生冲突?

发布于 2024-09-04 06:18:09 字数 200 浏览 12 评论 0原文

如果我理解正确的话,应用程序有时会使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

怂人 2024-09-11 06:18:10

有 2 个端口:源端口(浏览器)和目标端口(服务器)。浏览器向操作系统请求可用的源端口(假设它收到 33123),然后与目标端口(通常为 80/HTTP443)建立套接字连接/HTTPS)。

当 Web 服务器收到应答时,它会发送一个响应,该响应的源端口为 80,目标端口为 33123。

因此,如果您有 2 个浏览器同时访问 stackoverflow.com,您将看到如下内容:

Firefox (localhost:33123) <-----------> stackoverflow.com (69.59.196.211:80)
Chrome  (localhost:33124) <-----------> stackoverflow.com (69.59.196.211:80)

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:

Firefox (localhost:33123) <-----------> stackoverflow.com (69.59.196.211:80)
Chrome  (localhost:33124) <-----------> stackoverflow.com (69.59.196.211:80)
心作怪 2024-09-11 06:18:10

传出 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.

天涯离梦残月幽梦 2024-09-11 06:18:10

它是标识连接的五元组(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.

℡寂寞咖啡 2024-09-11 06:18:10

客户端通常选择 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)

陪你到最终 2024-09-11 06:18:10

浏览器是一种客户端应用程序,您可以使用它来查看通常位于不同计算机上的网络服务器上的内容。
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.

不必了 2024-09-11 06:18:10

您需要小心区分“侦听端口 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.

戈亓 2024-09-11 06:18:10

您在这里谈论的端口 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文