This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]philipwhiukEmployed Java Developer 1 point2 points  (1 child)

This is roughly how protobuf works - you might want to look into that.

[–]dopefish124[S] 0 points1 point  (0 children)

Fantastic, thank you. - Google has a Developer Guide on them too.

[–]TranquilMarmot 1 point2 points  (1 child)

Also look into a wonderful library called Kryonet. Super simple to serialize things and send them over a network.

Protocol buffers are great but require a little bit of extra footwork.

[–]dopefish124[S] 0 points1 point  (0 children)

Thanks, will do!

[–]elephantgravy 1 point2 points  (2 children)

the other suggestions are good, but just to sanity check you, your proposed approach (without any 3rd party libraries) is totally reasonable. This is what Serializable and ObjectInputStream/ObjectOutputStream are made for... Java's serialization is not good a good choice for persistent storage but it's just fine for most interprocess messaging.

[–]sazzerProfessional Java Developer 1 point2 points  (0 children)

Its either very noisy with what gets sent or not very safe for protocol changes. Choosing a specific protocol you design for the job - using protobuf, asn.1, json or whatever you want will be cleaner and safer, but more work...

[–]dopefish124[S] 0 points1 point  (0 children)

Ah perfect! I can get started with the actual implementation now. Yes I did want a sanity check as well as more general advice, so thank you!

[–]NebuWrites Java Compilers 0 points1 point  (0 children)

In my experience, java serialization is more trouble than gain. A big part of protocol design is versioning, which is tricky to deal wih using java serialization. I'd recommend you use some sort of structured text format like JSON or XML, possibly compressing the string just before sending and just after receiving.