Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple TCP connection on same IP and port

I have a very basic question about TCP.

Consider an application, say DEST, with IP Dest IP listening on port 6789.

Now I have 2 source applications which are capable of sending messages to this application DEST and they communicate via TCP protocol.

Say source system 1 is SRC1 and source system 2 is SRC2 with IPs SRC1 and SRC2 respectively.

Ideally only one of these source systems would be running and I can see that I have an active connection between SRC1 or SRC2 and DEST by executing the netstat command on the source system (netstat -nao | grep 6789).

Now just for heck of it I started the second source system as well and was surprised to learn that the result of netstat on both the source systems shows an active TCP connection with the application DEST listening on port 6789.

Result of netstat command on SRC1 and SRC2 servers:

TCP SRC1 IP:17678   DEST IP: 6789 ESTABLISHED

TCP SRC2 IP:51298   DEST IP: 6789 ESTABLISHED

I was under the impression that DEST application listening on IP DEST1 and Port 6789 can only have 1 active TCP connection (DEST server IP:6789 can have only 1 active TCP connection).

like image 449
Xavi Avatar asked Dec 01 '22 14:12

Xavi


1 Answers

If what you thought were true, web servers wouldn't work. Web servers basically listen on two ports: 80 for HTTP, and 443 for HTTPS. Web servers often have many thousands of clients connected at once.

The application can have many connections through one port. It can distinguish the connections by the source/port combination of the connecting host. In fact, each source host could have connections on multiple ports (the address is really a combination of address and port) to the same destination port, if the application supports it.

like image 50
Ron Maupin Avatar answered Dec 06 '22 02:12

Ron Maupin