c++ - Send() and recv() double or int -



c++ - Send() and recv() double or int -

i have problem send , recv double/int client server , server client. moment, have:

client:

cin>>xp; send( master,(char*)&xp,sizeof(xp),0);

server:

int valread, nr; char * buffer; valread = recv(s,(char *)&nr,sizeof(buffer),0);

and it's work, when send server client wrong.

i have on server:

int lol; lol=5; send(s, (char*)&lol, sizeof(lol), 0);

and want int on client:

bytesrecv = recv(master,(char*)&nr,sizeof(buffer),0);

i don't knwo why doesn't work :/ when cout/printf int on client it's 0 or 9,2555... please help :/

your sizeof(buffer) wrong - should send , receive sizeof(int).

also, note not work if server , client store integers in different order in memory - their endianness may different.

to create sure not problem, switch host network order , back. read htonl , ntohl

c++ winsock

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -