Daisetsu
Daisetsu

Reputation: 4976

Does a new socket open for every UDP connection?

I know that with TCP each connection creates a new socket. Does UDP also create a new socket for each connection?

Upvotes: 3

Views: 1789

Answers (2)

user207421
user207421

Reputation: 311039

I know that with TCP each connection creates a new socket.

You have that back to front. Each new socket represents a new connection.

Does UDP also create a new socket for each connection?

That doesn't make sense either. First there are no real connections in UDP. Second, it is you who creates the sockets, or your application. Not UDP. Or TCP.

Upvotes: 2

Jonathan Leffler
Jonathan Leffler

Reputation: 754940

No.

When you receive a message (recvmsg()), you are told the IP address of the peer that sent the message; when you respond (sendmsg()), you specify the IP address to which the message goes. This is done over a single socket. See also <sys/socket.h>.

Upvotes: 7

Related Questions