You can send the integer as four bytes, of course (or however many bytes your integer happens to be); but you have to be careful. See the function htonl()
, presented on your system probably in <arpa/inet.h>
.
Assuming a four-byte integer n, this might do what you want:
uint32_t un = htonl(n);
send(sockfd, &un, sizeof(uint32_t), flags);
Then you can code the complement on the receiving end.
The reason for the call to htonl()
is that the highest-order byte is conventionally transmitted first over the Internet, whereas some computer architectures like the ubiquitous x86 store the lowest-order byte first. If you don't fix the byte order, and the machine on one end is an x86, and the machine on the other end is something else, then without the htonl()
the integer will come through garbled.
I am not an expert on the topic, incidentally, but in the absence of experter answers, this answer might serve. Good luck.