#include <unistd.h>
ssize_t read(int fd, void *buf, size_t count);
-----------------------read - read from a file descriptor
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count);
----------------------write - write to a file descriptor
#include <sys/types.h>
#include <sys/socket.h>
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
--------------recv, recvfrom, recvmsg - receive a message from a socket
#include <sys/types.h>
#include <sys/socket.h>
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
---------------send, sendto, sendmsg - send a message on a socket
区别:
由函数原型可以看到:
1)头文件不同
read、write函数为unix系统标准函数;
recv、send函数为socket编程时使用函数;
2)函数参数个数不同
recv和send函数分别多了第4个参数flags
总结:socket编程中一般使用recv和send函数。
本文详细对比了Unix标准函数read/write与socket编程专用函数recv/send的区别,包括头文件、参数数量及应用场景的不同,强调在socket编程中recv与send的使用更为广泛。
2597

被折叠的 条评论
为什么被折叠?



