A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-07-26 11:34 PM

From: Colombia
Registered: 2002-06-12
Posts: 353

Re: 5.2 - Difference between "connected" and "unc

From Andrew Gierth (andrew@erlenstar.demon.co.uk):

If a UDP socket is unconnected, which is the normal state after a bind() call, then send() or write() are not allowed, since no destination address is available; only sendto() can be used to send data.

Calling connect() on the socket simply records the specified address and port number as being the desired communications partner. That means that send() or write() are now allowed; they use the destination address and port given on the connect call as the destination of the packet.

From: Sanjay Pujare

I have another question: When I "connect" a UDP socket to a remote addr and port, is there a corresponding "accept" at the other end for my "connect" to go through? I know that when a TCP socket is connected, the connection happens when the server "accept"s the connection. What is the equivalent thing for UDP sockets?

From: Rob Seace

No, there is no real equivalent to accept() for UDP... UDP
is inherently a connectionless protocol; doing a connect()
on a UDP socket is simply a convenient kluge, to allow doing
write()/send(), as Andrew says above... It merely presets
the remote destination address, so you need not specify it
every time, via sendto()/sendmsg()... But, it doesn't
initiate anything special on the remote end... The remote
doesn't know the difference, one way or the other...


Board footer

Powered by FluxBB