The sendto
function is the one that's generally used for UDP sockets. As UDP is connectionless, this function allows you to specify the IP and port that each outgoing packet is sent to.
You can however also use send
if you first use connect
. The connect
function can be used to specify the destination IP and port for all packets sent using send
. It also restricts the packets you receive to just those from that IP/port. The connect
function may be called multiple times to change the associated remote IP/port, or to remove the association.
In general, I would recommend sticking with sendto
as it gives you more flexibility over who you're sending to.