I got a struct for client and server like this:
{
char type;
int payloadLen;
char fileName[50];
int fileIndex;
int blockOffset;
int blockLen;
char streamingData[MAX];
int h264fileLayer;
}
in client I recv data like
memset(&data_recevied, 0, sizeof(data_received);
recv(sockfd, (char *)&data_received, sizeof(data_received), 0);
I use this to receive file sent from server,everything works fine for the first leading couples of files,then it broke,I checked the struct when it broke, seems the struct it received is a mess,and fileIndex is way too large,however the client program works fine in Windows with winsock lib,no broken at all.
I think this has something to do with cross-platform,maybe there is something I missed,really could use help here, thanks
It is not good idea to send this kind of structs between programs. With luck it may work.
There is couple reasons that may cause the problem:
You can try to remove padding (alignments) by using:
Linux:
Windows:
If still problems, then use
int32_t(or some other fixed size type) instead of int.