Does a new socket open for every UDP connection?
I know that with TCP each con开发者_StackOverflow中文版nection creates a new socket. Does UDP also create a new socket for each connection?
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>
.
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.
精彩评论