If you are only sending data through the Java JVM, then any choice is possible.
A textual representation (XML, JSON, or custom) has several advantages:
- easier to make it compatible between Java and other languages
- it is less fragile in the face of version changes or several different versions of your code at each end of the socket.
- It is much easier to check and debug.
Depending on the format, this may be slightly slower, but it is often not significant.
source share