I am currently building a distributed system that consists of two separated nodes, connected over wireless Lan.

The processes communicate over a bidirectional TCP Socket and JSON messages.

For the application, it is quite crucial that all transmitted messages arrive at the receiver consistent in the correct order. Beside this, it is not tragic if there is a transition delay (caused by the network).

Since I am not that familiar with network communication protocols, I ask myself if I must build in additional security mechanisms to ensure that no inconsistent message arrives (incomplete JSON message). Currently I only use a message counter, which I embed into the JSON message.

As socket implementation I use the standard Java socket class (java.net.Socket)

Do you recommend any further methodologies or is the consistence ensured by the ISO/OSI stack?

Best regards


TCP guarantees that packets will arrive at your application in order - that's one of the main differences between TCP and UDP. If necessary, the TCP stack will buffer up out-of-order packets, and re-sort them before delivering them on to the application.

But if the network goes down, then the connection will drop. If that happens, any un-received packets will be lost. So it's always possible that you could get the start of a message, but not the end.

Tangentially related, make sure you consider the possibility of a malicious person setting up fake nodes that send out bad data. TCP by itself doesn't really guard against unwanted connections to the server side of the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.