0

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

Ewan
  • 70,664
  • 5
  • 76
  • 161
Euestros
  • 9
  • 1
  • Have you done a search on what TCP does for you? https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Network_function seems to answer your question. – Bart van Ingen Schenau May 23 '19 at 10:16

1 Answers1

2

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.

Simon B
  • 9,167
  • 4
  • 26
  • 33