客户端:
char buf[1024];
int packetAmt = fileSize/PACKETSIZE;
cout<<"Number of packet amounts: "<<packetAmt<<endl;
// send packet amount to serv
ibytessent=send(s,itoa(packetAmt,buf,10),sizeof(buf),0);
服务器端:
char szbuffer[1024];
if((ibytesrecv = recv(s1,szbuffer,sizeof(szbuffer),0)) == SOCKET_ERROR)
throw "Receive error in server program\n";
cout << "This is the number of packets sent: " << szbuffer << endl;
packetAmt=atoi(szbuffer);
cout << "This is the number of packets sent: " << packetAmt<< endl;
将 char 数组转换为整数后返回的整数与发送的字符串不匹配。但是打印字符串将返回正确的值。我也尝试过使用 strtol 函数。从整数转换为字符数组时会出现错误吗?