I need to send a lot of sets of data over a network. These sets of data include two floats and an 16 character string. I thought about packing the bits together, but I would like to know the best way to do so. Any ideas?
CopyableCougar4
I need to send a lot of sets of data over a network. These sets of data include two floats and an 16 character string. I thought about packing the bits together, but I would like to know the best way to do so. Any ideas?
CopyableCougar4
ignore this until your game is complete, and you metering shows that the bandwidth consumed is a major factor.
Not sure how you would even achieve bit packing… floats are 32 bits and java chars are 16bits.
Depending on the nature of the data and any latency requirements… it might be as simple as just using GZipOutputStream and GZipInputStream.
“Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth
Moogie, if the data is just a couple of numbers and a short string, compressing the data will make it larger.
If your Huffman tables are precomputed for a representative set of the data to be sent you can have them on both sides of the communication and avoid sending them, mitigating the setup cost for Gzip. But what a palaver. Do as ddyer says, and wait till it’s a problem.
Cas
of course that is true, however the OP has stated large amount of data… so if there is any simple correlation within the data then simple GZip streams would work as a quick and simple starting point
Elaborating on Cas’s idea… if you know the probabilities of the data then huffman encoding… or better yet arithmetic encoding might yield better compression.
How much data are we talking about? What is the context of both the data and the situation that the data is being sent in? compression only really works when you know the data.
well its not really a lot of data , you are barely even getting near a 10th of a KB , modern bandwidth could handle you sending that data 60000000 times before any latency issues would occur , if its that small you really shouldnt worry if is the coordinates of a lot of your players an option might be to instead send the data once , and then only send events to the other client alerting it of any changes such as names.
Your description was vague , you need to say if you are using a server or client to client connection , that way the amount of latency and the data you send can be changed.