Network byte order
If i am transferring data between little endian and big endian computers, i need to call htons() etc. on my shorts and longs. I am assuming i would still need to do this even if i am converting everything to an array of bytes before sending it? If so, how do i get a correct byte order for float''s, double''s etc. that aren''t longs or shorts? Or do i just have to make sure that if i am going to use data other than only bytes shorts and longs, i will only run the program on little endian systems?
Thanks
Just do some casting magic:
You can do it with unions too (which might be cleaner).
float Float;long NetworkFloat;NetworkFloat = htonl( *((long *)(&Float)) );
You can do it with unions too (which might be cleaner).
You shouldn''t be sending floats across the network in the first place. The bit layout of floats can vary a lot between different machines, so basically you can either scale your values and send them as integers (of course, that only works if your floats aren''t really _floating_ point), or you will have to deal with the per-CPU-type internal layout of floats. Good luck.
cu,
Prefect
Return to the Shadows
cu,
Prefect
Return to the Shadows
Widelands - laid back, free software strategy
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement