how can an application use port 80/HTTP without co

2019-01-10 04:54发布

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.

7条回答
地球回转人心会变
2楼-- · 2019-01-10 05:06

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.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-10 05:14

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-10 05:18

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)

查看更多
放我归山
5楼-- · 2019-01-10 05:24

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.

查看更多
Lonely孤独者°
6楼-- · 2019-01-10 05:25

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.

查看更多
Evening l夕情丶
7楼-- · 2019-01-10 05:27

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 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)
查看更多
登录 后发表回答