有了解linux下socket编程的吗?
请问我用send()函数发送信息,每次能够发送多少字节的内容呢?
如果我要发送的信息量很大,是不是会分次发送?
int send(int sockfd, const void *msg, int len, int flags);
len就是这次发送需要发送的信息的长度
如果send一次没有把全部信息量发送完,那我客户端就需要写个循环语句判断是否接收recv()完全部信息量。但是我客户端不知道服务器想发给我多少信息量,我应该怎么写这个循环语句呢?还是说send()里的int len就把服务器想要发送的信息量长度也发给了客户端,所以客户端就知道了服务器想要发送多少?
[解决办法]
看手册:
When the message does not fit into the send buffer of the socket, send normally blocks, unless the socket has been placed in non-blocking I/O mode. In non-blocking mode it would return EAGAIN
[解决办法]
1,自定义协议.
2,close/shutdown(SHUT_WR)/会引起对端read返回0.