ok im having a few issues with this. I pack the message length and the message into the buffer and send it, the size of the message is 14. but when it gets to the other side and i read in the size it says its 1681989646. here is the send and recv code for this.
Code:
//packing and sending
char *message;
message = (char *)malloc(strlen(username) + strlen(password) + 3);
memset(message, '\0', sizeof(message));
message[0] = LOGIN; strcat(message, " ");
strcat(message, username); strcat(message, " ");
strcat(message, password);
char *buffer;
int size = sizeof(int) + strlen(message);
buffer = (char *)malloc(size);
memset(buffer, '\0', sizeof(buffer));
memcpy(buffer, &size, sizeof(int));
strcat(buffer, message);
allegro_message("size: %d", size);
allegro_message("Message to server: %s", buffer);
nlWrite(LocalSocket, buffer, sizeof(buffer)); //same as send(LocalSocket, buffer, sizeof(buffer), 0);
and
Code:
//recieve and unpack
int messagelength;
while(nlRead(newsock, (void *)&messagelength, sizeof(int)) <= 0) //same as recv(newsoc, (void *)&messagelength, sizeof(int), 0);
{}
cout<<"Messagelength: "<<messagelength<<endl;
char* buffer = (char *)malloc(messagelength);
while(nlRead(newsock, buffer, messagelength) <= 0)
{}
cout<<"Buffer: "<<buffer<<endl;
any ideas why im getting the wrong number?
thanks