Port number is a local property and helps identify a socket endpoint for an incoming data destined for that port on the receivers machine. Each machine has 64K ports for each protocol type (TCP or UDP) and for each family type (IPv4 or IPv6).
With UDP, it is possible to send to (and receive from) many clients sitting on different ports. So, for the following connection:
UDP_socketA (port p1) <---------> UDP socketB (port p2)
|
|
|
|
UDP socketC (port p3)
Thus, socketA can send datat to socketB and socketC even though they are sitting on different port numbers. The way it works is that with UDP sockets, we typically use sendto() API that allows us to specify an IP address and a port number for each packet. Thus, we can send one packet to port B and the next packet to port C and what not.
With TCP, however this is not the case. Once a connection is established, let us say between socketA and socketB, then there is no way, either of these sockets can talk to socketC
TCP_socketA (port p1) <---------> TCP socket B (port p2)
|
|
|
|
TCP socketC (port p3)