Having trouble sending floats with socket_send
I am trying to send various data and especially floats with socket_send but I am having trouble doing so. socket_send seem to prefer strings and Id rather not want to convert my floats to actual text representation of the values. Does anyone have any tips about how to properly do this or some workaround? P.s I read that socket_send2 should be able to handle 0 values at least but I cant seem to find this function either, did this get dropped in version 1.65 or did this handling get included in the socket_send?
|
i think all data has to be sent this way. try this:
Code:
|
Hmm... that would send the float as actual text, which is what I am trying to avoid. If I could send the actual bits of the float that would save me a lot of bandwidth.
|
do cell packing.
Code:
The _: will strip the tag off and the float will be binary data. then just stuff it into the array. Note: socket_send() will terminate on a null byte, this is fixed in 1.65 with socket_send2(). |
Thank you, this was exactly what I was looking for =)
+karma for you. |
I ran into one more problem, Now that 1.70 is out and socket_send2 is here (Thanks Bailopan), I thought I would continue working on this. Problem was I could not simply stuff the integers or floats into one cell like this:
MyPacket[X] = _:var (for floats) or MyPacket[X] = var (for ints) Because it still only make it one byte large and the Ints are 4 bytes large (32 bit). I solved it like this: Code:
new myInt[4];MyPacket[X] = myInt[0]; MyPacket[X+1] = myInt[1]; MyPacket[X+2] = myInt[2]; MyPacket[X+3] = myInt[3]; (a little bit more fancy than above, but the same principle) Maybe there is a better way to do this than with logic operators but if there isn't I hope this can help. I thought this might be helpful for someone else trying to send binary data over sockets, for me it works like a charm. Cheers! |
| All times are GMT -4. The time now is 20:28. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.