I have tried writing to a socket using write() command. The data I need to write is of structure type and it contains both char and int datatype values. But when I write the data to the server socket, the value of the int variable is getting corrupted. I am receiving a value as 16777216 always.
I am writing from a Solaris machine to a Linux machine. Solaris is a 32 bit machine and Linux is a 64 bit machine. Do this have any impact on my problem.
I used htonl/ntohl and vice versa for passing the integer values from and to the server. But how can I use this if I am writing the whole structure type into the socket?? Can anyone help me to sort this out??
PCHAR data = NULL;
int size = sizeof(WSMsg);
int retry = 10;
data = new char [sizeof(WSMsg)];
memcpy(data, msg, sizeof(WSMsg));
int n = write(fd, &data, size);
This is my code part. Here WSMsg is of structure type and has int and char type values.