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?
Asked
Active
Viewed 1.1k times
20
-
@Neil's comment is completely incorrect. You *can* have two different sockets using the same endpoint, as long as they use different protocols. TCP and UDP ports occupy different spaces. Any two processes can open the same port as long as one is TCP and one is UDP, and the bind-address is irrelevant to that. – user207421 Sep 16 '21 at 10:20
-
@user207421 I commented on this? I guess it must have since been flagged and deleted... it's annoying that I still get a notification for a reply to a comment that no longer exists... – Neil Sep 16 '21 at 13:31
-
@Neil I flagged it and somebody deleted it. The ways of SO are strange indeed. – user207421 Sep 17 '21 at 00:04
3 Answers
26
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.

Rick Giuly
- 983
- 1
- 14
- 19

cxxl
- 4,939
- 3
- 31
- 52
13
TCP ports and UDP ports are not related to each other at all.

Ben Jackson
- 90,079
- 9
- 98
- 150
-
14To answer the question directly, yes, you may have two different processes binding to the same socket and to the same port but one with UDP and one with TCP. The UDP and TCP port namespaces are totally independent, despite the fact that they are in the same numerical range. – Matthew Hall Nov 25 '12 at 01:35
0
Yes. Two sockets can bind same port number but different protocol.
It's not the same port, just happens to have the same number.

scravy
- 11,904
- 14
- 72
- 127
-
Or perhaps better said that it is the same port but not the same socket? – ankush981 Sep 12 '21 at 16:28
-
@ankush981 I edited in that `two sockets can bind the same port number` – scravy Sep 16 '21 at 09:25
-
@ankush981 It isn't a socket at all. It's a port. It's only a socket inside the application. – user207421 Sep 16 '21 at 09:44