I have a Struct to send over a socket to a client. Both the Client and the Server is on the same architecture so there is no endian problem. I receive the int values properly. But not able to receive the char[] values properly. This is the structure.
struct Packet {
int id;
int number;
char data[256];
};
In the Server side I serialize the data and write to the client.
struct Packet *s = new Packet();
s->id= htonl(1000);
s->number= htonl(7788);
memcpy(s->data, "MESSAGE", 7);
n = write(NewSockFD , s ,sizeof(s) );
In the Client side I deserialize the data.
n = read(SockFD , Buffer , sizeof(Buffer));
struct Packet *s = (struct Packet*)Buffer;
char b[256];
int i = ntohl(s->id);
int j = ntohl(s->number);
memcpy(b, s->data, sizeof(s));
I receive the id and number values correctly. Problem is with the data value. What I'm doing wrong here??..