C++ socket programming: packing data from an array of different types -
i'm new socket programming in c++, , while have basics down, i'm having trouble tackling following situation:
i have function consumes array of void pointers (i.e. void **). each pointer pointing different standard c data type (i.e. char, int, short, long, float, double). array of variable length, have access length , type of data each pointer pointing to.
the goal of function send data pointed pointers. question is: there way send in 1 go?
by way, know send() doesn't guarantee delivery of every byte. have helper function loops , invokes send() many times needed. question has packing , serializing data.
if want send integer, invoke htons() or htonl() in order convert data network byte order.
if want send variable length string, send length of string first followed actual string. easy enough.
but if want send variable amount of data, in 1 go (assuming have helper guarantee delivery of every byte), data comes array of pointers different c standard data types? again, know i'll want send length of data first, no problem because know length , type of each pointer in array. don't know how pack ensure it'll in network byte order.
Comments
Post a Comment