我正在尝试通过 TCP 套接字发送一组数字,但它们输出不正确。我无法弄清楚为什么它没有收到正确的数字。这就是我所拥有的...
客户
// the number array to be sent
unsigned long numArray[10] = { htonl(1), htonl(2), htonl(3), htonl(4), htonl(5),
htonl(6), htonl(7), htonl(8), htonl(9), htonl(10) };
send(s, &numArray[0], sizeof(numArray), 0);
服务器
// get the array of numbers
unsigned long numberArray[10];
int numberData = recv(new_fd, numberArray, sizeof(numberArray), 0);
if(numberData == -1) {
cout << "ERROR" << endl;
}
unsigned long* num = numberArray;
for(int i = 0; i < sizeOfIncomingData; i++) {
// this outputs a bunch of huge numbers, none of which are right...
cout << ntohl(*(num+i)) << endl;
}