- How do
sendto()
andrecvfrom()
differ fromsend()
andrecv()
?
The send()
and recv()
functions are useful after calling connect()
. They only work with the one remote address that was passed to connect()
. The sendto()
and recvfrom()
functions can be used with multiple remote addresses.
- Can
send()
andrecv()
be used on UDP sockets?
Yes. The connect()
function should be called first in that case. However, the sendto()
and recvfrom()
functions are often more useful for UDP sockets.
- What does
connect()
do in the case of a UDP socket?
The connect()
function associates the socket with a remote address.
- What makes multiplexing with UDP easier than with TCP?
One UDP socket can talk to multiple remote peers. For TCP, one socket is needed for each peer.
- What are the downsides to UDP when compared to TCP?
UDP does not attempt to fix many of the errors that TCP does. For example, TCP ensures that data arrives in the same order it was sent, TCP tries to avoid causing network congestion, and TCP attempts to resend lost packets. UDP does none of this.
- Can the same program use UDP and TCP?
Yes. It just needs to create sockets for both.