One thing I know I have wrong is encoding the data, I know I am just sending a string through the socket instead of Hex, which I’m sure requires a lot more bandwidth. Does anyone know how I can specifically send Hex through TCP sockets?
I was actually hoping to send Bytes directly as individual 1’s and 0’s, to compress the amount of data being sent. I’m unsure of how to turn Hex into Bytes though. Looking at the Bytes class it seems there is no way to create a Bytes variable from Hex though, or even 0’s and 1’s.
openfl.utils.ByteArray is an interface for haxe.io.Bytes you could use as well for writing shorts, floats, ints, strings or bytes as you wish. For example:
byteArray.writeByte (0); // abstract enum value AB
byteArray.writeInt (1); // id
byteArray.writeFloat (50); // x
byteArray.writeFloat (100); // y
Just pay attention to the endianness of the server and your byteArray
For an abstract enum, you could use something like:
@:enum abstract ServerCommand(Int) from Int to Int {
var AB = 0;
...
}
That way you can use an ordinary enum in your Haxe code, but when you send it to the server, you can read or write it as an ordinary Int