Reputation: 575
How send a long through a socket? and How to receive it?
Server:
long size;
f = fopen("file.txt","r");;
fseek(f,0,SEEK_END);
size = ftell(f);
rewind(f);
printf("Size: %ld Bytes\n",size);
/* send "size" with send method */
send(socket,???,???,0);
Client:
long size;
recv(socket,???,???,0);
Thanks to all for the help.
Upvotes: 0
Views: 389
Reputation: 225162
Assuming the same endianness and sizeof(long)
on both sides of the connection:
send(socket, &size, sizeof size, 0);
and:
recv(socket, &size, sizeof size, 0);
Those assumptions may not be correct, though, so be careful.
Upvotes: 1