1.recv多次调用问题
记录一下今天突然想到的一个recv多次调用问题,如下:
server代码:
...
char buf[100] = { 0 };
cout << "start recv " << endl;
int rc = recv(sockConn, buf, 100, 0);
cout << "has recv " << rc << endl;
...
client端代码:
char buf[10] = { "123456789" };
int sd = send(s, buf, 10, 0);
cout << "has send " << sd << endl;
sd = send(s, buf, 10, 0);
cout << "has send 2:" << sd << endl;
这里send发送了两次,每一次都是10个字节,server端的buf是100个字节,为啥server端要接收两次?? (通过getsockopt可知,send和recv的缓冲器大小都是8092字节)
原因: