For three hours I have been trying to find a solution; I need to send the number of unsigned long long from client to server using the smallest bytes

Do so

Customer:

unsigned long long n = 18446744073709551500; send(sock, (char *)n, 8, 0); 

Server:

 char t[7]; recv(sock, t, 8, 0); unsigned long long n; memcpy(&n, t, sizeof(unsigned long long)); printf("%llu\n", n); 

Server output: 14757395258967641141

I have already tried a lot of things, maybe someone knows, I'm not strong at si, sorry for the stupid question

    2 answers 2

    You missed the pointer, just add & to the client code:

     unsigned long long n = 18446744073709551500; send(sock, (char*)&n, sizeof(n), 0); 

    Server code:

     unsigned long long n; recv(sock, (char*)&n, sizeof(n), 0); printf("%llu\n", n); 
    • It was the first option that I took from the textbook, but the studio gave me this: "unsigned long long * type argument is incompatible with the" char * "type parameter Maybe you need to change something in the settings? - Alexander
    • there was a Client in the textbook: send (sock, (char *) & n, sizeof (n), 0); Server: recv (sock, & n, sizeof (n), 0); - Alexander
    • upd: added casting to (char *) - greenee
    • Thank you, it worked for me - Alexander

    You receive 8 bytes in a 7-byte buffer, at least the problem may be here

    • This was as an experiment, I forgot to correct it back, the fact is that the same thing was output for any buffer sizes - Alexander