帮忙看看一个小问题!
接收端:
char szBuff[256];
int ret;
while(1)
{
ret = recv(sock,szBuff,256,0);
if (ret == 0)
break;
else if (ret == SOCKET_ERROR)
{
printf("recv error %d\n", WSAGetLastError());
break;
}
szBuff[ret] = '\0';
printf("RECV: '%s' \n",szBuff);
}
return 0;
}
发送端:
strcpy(szMessage,"hello,nice to see you!");
for (i = 0;i < 20;i++)
{
ret =send(sClient,szMessage,strlen(szMessage),0);
if (ret == 0)
break;
else if (ret == SOCKET_ERROR)
{
printf("send error");
break;
}
printf("Send %d bytes\n",ret);
}
为何接收端总会把前几个“hello,nice to see you!”连在一起。而接下来得都是
显示正确的。
即结果是:
RECV:'hello,nice to see you!hello,nice to see you!hello,nice to see you!'
RECV:'hello,nice to see you!'
RECV:'hello,nice to see you!'
RECV:'hello,nice to see you!'
RECV:'hello,nice to see you!'
.
.
.