I'm working on a couple of programs, client/server. I'm using winsock library to handle data transfer between the two programs. I'm having a problem when it comes to sending int values, they must be converted to (char *) since that's the data type of the buffers used in the socket Send() and Recv() functions. to elaborate, consider the following:
Client side:
-----------
unsigned char rnd[4];
int noncer =0;
// Generating a random number
RAND_pseudo_bytes(rnd,sizeof(rnd));
noncer = (int)rnd;
non1=(char*)noncer;
// These two lines produce the same output which is 1244556
cout <<"\n Noncer :" << noncer << "\n";
cout.flush();
cout <<"\n Noncer char :" << (int)non1 << "\n";
cout.flush();
SendData(Socket, non1);
Server Side:
-----------
int client_nonce;
char String[50];
String_initialization(String);
Don't play around with casting like that unless you know what you're doing. Type punning can be tricky business, but barring transmission issues with your sockets, this should work:
Hi I am having the same problem, but I couldnt solve it.
I need to send a CString with Unicode (16bit) to the send and recv function. Unfortunately all i get is garbage
Any help is welcomed
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.