Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How two browsers simultaneously listen on port 80?

Tags:

sockets

When I try to bind socket to port 80 from program I get error, but how two browsers simultaneously could listen to same port 80 ?

like image 738
Xinus Avatar asked Dec 21 '09 11:12

Xinus


People also ask

Can we use same port for 2 listeners?

The short answer is “no, not on the same host." The longer answer is that this is by design, the basic rationale being consistency.

Can multiple applications use port 80?

The port will only need to be used once in order to communicate what dynamic port will be used for the rest of the session. This is a problem for both network connections and for connecting several applications on the same computer.

Can you use two different browsers at the same time?

Is it safe to run multiple browsers at the same time? Yes. All browsers act independently, allowing you to run multiple browsers at the same time. The only issue you may experience is browsers "fighting" over which should be the default.

Do web servers listen on port 80?

On a Web server or Hypertext Transfer Protocol daemon, port 80 is the port that the server "listens to" or expects to receive from a Web client, assuming that the default was taken when the server was configured or set up.


2 Answers

Browsers do not listen on port 80, HTTP servers do (although that's just convention, you could easily have an FTP or telnet server using port 80).

In TCP/IP, a "session" must be unique and the session is defined as the 5-tuple (protocol, sourceIP, sourcePort, destinationIP, destinationPort). This allows the packets to be routed correctly on the internet.

Typically when a client attempts to contact a server, it specifies 0 as its source port which means that the operating system assigns it an unused one. That means that the client will actually listen on that port rather than port 80.

So you may get a session with the properties (TCP, mybox.com, 1101, www.microsoft.com, 80) when your browser goes out to access Microsoft's web pages.

If you find you cannot bind your server to port 80, it will most likely because you already have a server running on that port, or your program doesn't have the required privileges to bind to that port (ports less than 1024 are generally considered privileged ports).

Running netstat -a (on Linux or Windows) will tell you whether a server is bound to port 80. Look for a listener on port 80 (or http if it's resolving ports to service names), something like:

tcp  0  0  localhost:http  *:*  LISTEN
like image 180
paxdiablo Avatar answered Sep 23 '22 18:09

paxdiablo


They don't listen on port 80 they talk to port 80, or 443 if you're using SSL (or on any other port if the admin broke with convention, you may have seen urls like http://www.site.com:8080 where the site has been set up on port 8080).

The browser will make the request from a random high-numbered port so more than browser can be active at the same time.

As paxdiablo says, you can use netstat to see what programs are listening for connections (using "netstat -a -b" will show which executable is bound to which port)

like image 34
wefwfwefwe Avatar answered Sep 22 '22 18:09

wefwfwefwe