mercredi 4 mars 2015

How do I serialize a struct of 8bit integers for socket programming?


I have a struct that has 5 unsigned 8 bit integers that mimics a frame with 5 packets. After researching, I know need to serialize the data, field by field, especially since I am sending from a Windows machine to a Linux machine and back.


here is my struct:



typedef struct pressure{
UINT8 a;
UINT8 b;
UINT8 c;
UINT8 d;
UINT8 e;
}pressure;


The issue is I cant use htons() since my members must be 8 bits. How do I manually serialize this? It would be greatly appreciated if you could provide a short code sample that shows how to serialize and what to pass to send().




Aucun commentaire:

Enregistrer un commentaire