I'm using synchronised sockets with a win32 window, and using the send() and recv() function to send data over internet TCP;
what i'm wondering, how would i send some integers or even my own class/structure over the tcp socket? because the send() function only lets me send characters.
Would i just have to send characters and then maybe convert them to integer with atoi()? or if i wanted to send a class structure, would i send many strings over and then put them in the variables.. one by one.
It isn't sending characters in the textual sense - it's sending contiguous arrays of bytes, which it refers to using a char*. You can point to the bytes of any value type this way, so if you wanted to send an int,
int A = 5;
const char* pBytesOfA = (const char*)&A;
int lengthOfBytes = sizeof(A);
send(socket, pBytesOfA, lengthOfBytes, flags);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With