ssize_t send(int sockfd, const void *buf, size_t len, int flags);
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
send函数一般用于TCP链接,sendto函数一般用于UDP连接。
来看看man手册里怎么说send与sendto:
The send() call may be used only when the socket is in a connected state (so that the
intended recipient is known).
The only difference between send() and write(2) is the presence of flags. With a zero
flags argument, send() is equivalent to write(2). Also, the following
callsend(sockfd, buf, len, flags);is equivalent tosendto(sockfd, buf, len, flags, NULL, 0);
If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) socket, the arguments dest_addr and addrlen are ignored (and the error EISCONN may be returned when they are not NULL and 0), and the error ENOTCONN is returned when the socket was not actually connected. Otherwise, the a