Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP and UDP same ports, different process

I know you can't have two different process using the same port, but what happens if one is using tcp and the other one udp? Can you have two different process each one binding a socket to the same port but different protocol?

like image 763
Cristiano Coelho Avatar asked Nov 25 '12 00:11

Cristiano Coelho


People also ask

Can UDP and TCP use the same port at the same time?

Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53 and tcp/53.

Can different processes use the same port?

You can make two applications listen for the same port on the same network interface. There can only be one listening socket for the specified network interface and port, but that socket can be shared between several applications.

Can two services run on same port?

It is possible. You just have to bind on the right IP address/interface each service using the same port. Ports (be them UDP or TCP) have their own pool per IP address. You can listen on the same port if you change: IP address or protocol (UDP or TCP).


1 Answers

The 5-tuple (protocol, source ip, source port, dest ip, dest port) must be unique. That means that not only can you have TCP and UDP using the same port number, but even outgoing connections with the same protocol and local port number, but different destinations.

When listening however, sockets usually must be unique in their protocol, i.e. you can/should not open another TCP socket with the same port number.

like image 143
cxxl Avatar answered Sep 19 '22 13:09

cxxl