difference between send() and sendTo() in C for a UDP network implementation

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.

posted @ 2022-12-16 14:31  fire909090  阅读(17)  评论(0编辑  收藏  举报