mst
mst

Reputation: 1

How web server handles connections which are same ports & IP Addresses?

I open IE explorer & Chrome in my computer and type localhost:80 and I get the index page.

Here I think my machine's IP is same to both connections (IE explorer & Chrome) and ports are too (80). Note: Source port will be different (as destination is same: localhost IP), this is my second question.

  1. So how webserver (lets say apache) handles this port 80 connections without failing? Does it port forwarding? In OS level even I tried with addr re-use, port re-use parameters and it is all same we cannot make multiple connection with same IPs & ports.

  2. Now, probably you have came up with a solution: although source ports and IPs are same, destination port is different in package: <protocol>, <src addr>, <src port>, <dest addr>, <dest port>. A. I got 49483~50004 ports as you can see on image. How client knows which destination port (49483~50004) is bound by webserver? If it is random between 0 and 65355 the webserver always binds all ports, it is very resource consuming. How webservers avoid from this?

Look at this image: command prompt-> netstat

If this question is related with low level sources it is OK, I understand Embedded TCP/IP/UDP, Phy MAC communication and package structures.

Upvotes: 0

Views: 341

Answers (2)

hcarrasko
hcarrasko

Reputation: 2352

All http request by default call to servers in the port 80, because servers listen by default in that port. So you only give an IP or hostname and the web browser add the default port (80). You can give a custom port if you web server is listenning in another port (usually Tomcat listen by default in 8080) for example you call it in: http://www.youamazingweb.com:8080.

A good example is see the IP as the home and the port is the door where clients enter to consume some resource hosted in server.

Upvotes: 0

user207421
user207421

Reputation: 310957

You have this all back to front.

  • All the port numbers at the server are the same: 80. So the client only has to know port 80.
  • All the port numbers at the client are different: 49483-50004 etc. So there is no ambiguity in the connection, because the 4-tuple you mentioned is unique.

Upvotes: 1

Related Questions