I have to transfer objects in Java through network using UDP datagrams. What format would be better in terms of overhead, no of bytes consumed, speed?. I have tried using Serialization and came to know about JSON. Which one would be better?
Asked
Active
Viewed 2,940 times
3

Simeon Pilgrim
- 22,906
- 3
- 32
- 45

Vamshi
- 437
- 6
- 14
-
1plenty of options that are faster than json - protobuf and kryo to name a few – radai Jun 29 '14 at 05:31
-
This depends immensely on the specific characteristics of the data in question--size of messages, number of messages per datagram, throughput, loss acceptability... – chrylis -cautiouslyoptimistic- Jun 29 '14 at 05:37
-
This is a pretty vague question. What is better or "best" in this case depends a lot on the data you want to transmit. Do you need flexible data formats, or are you always sending the same kind of data? Is space more important than speed? Also UDP has a maximum datagram size, so you have to make sure not to exceed that, or break things up into more than one UDP packet. Of course, once you do that, you have to worry about UDP packet loss, etc. Having said that, I agree with radai -- protobuf is pretty good, and has a lot of support behind it. – Bernie Habermeier Jun 29 '14 at 05:40
-
I have made classes for packet format's . So i just have to place the data inside packet object and send the object in one Datagram. – Vamshi Jun 29 '14 at 05:40
-
Yes, I am worried about the size of datagram. Will converting objects to JSON will have less size than the serialized byte stream? – Vamshi Jun 29 '14 at 05:42
-
I have Strings, Arraylists, boolean variables, integers in the packet format classes. – Vamshi Jun 29 '14 at 05:43
-
You should probably be looking at Google Protocol Buffers. – chrylis -cautiouslyoptimistic- Jun 29 '14 at 06:04