Terminal User
Terminal User

Reputation: 883

Can multiple sockets be associated with same port for UDP?

I think multiple sockets can be associated with same TCP port.

But can the same thing work for UDP?

Upvotes: 16

Views: 22262

Answers (2)

caf
caf

Reputation: 239041

Yes, it is also possible to have multiple sockets using a single UDP port.

Upvotes: 7

user207421
user207421

Reputation: 310913

The only way to associate multiple sockets with a port in TCP is by listening and then accepting.

The purpose in that case is to give every incoming client a unique socket so as to keep their byte streams separate.

You don't need that in the case of UDP because there are no byte streams. You can write an entire UDP server using a single UDP socket. You just read, despatch to a handler for that client, the handler writes the response back via the same socket.

Upvotes: 13

Related Questions