I am currently working on a project that require me to communicate between several Raspberry Pi's and a computer. I'll display data that sent by Raspberry Pi on that computer. Since I am using Raspberry Pi, I thought I can take advantage of using network layer protocols. Therefore, I concatenated almost thousand float numbers as a string and send it over Local Area Network using UDP protocol. At computer's side, I am parsing those float numbers from string and showing them as live data plots. This process is not for one time, it's working in a loop. I haven't seen any problems so far but my question is "Is there a way to make communication more relaible? What would you use for that?"

  • 3
    TCP, Small packets, short cables. – Lior Bilia Sep 14 at 10:42
  • 2
    TCP is 'more reliable' over a WAN than UDP, though there might be not much effective difference in a small LAN. – Neil_UK Sep 14 at 10:43
  • 1
    Consider MQTT. It's small, simple, reliable (on top of TCP), and easily interfaced from command line (helpful for debugging). – domen Sep 14 at 10:52
  • 1
    Modbus TCP IP is an industrial standard used widely. – Marko Buršič Sep 14 at 11:12
  • 1
    UDP protocol has no guarantee of delivery .... you would have to implement error checking and re-transmission in your code – jsotola Sep 14 at 15:45
up vote 4 down vote accepted

As stated in the comments, TCP is overall a better choice than UDP when it comes to reliability.

UDP is lightweight and with a lot less overhead than TCP. Once you send a UDP message, you do not expect a return message that confirm whether the message was received or not. To give you a practical example: UDP is used in video games a lot because it reduces the latency and the graphical engine can live up with a loss packet. When players play online they bombard the network with crazy amount of small packet.

There is other implementation that can stack on top of the TCP protocol, but this will be linked to specific requirement and use case scenario.

TCP on the other hand is a heavyweight protocol with reliability in mind. Each packet contains a lot more of overhead to prevent corruption and to ensure that the data was received properly. It is mandatory that each TCP message received is confirmed to the sender. This means that one packet will create two transmission.

Back to your question, on a local network with few data transfer, you will probably never see any difference and will likely only drop a packet once in a while. If you update quite frequently, but dropping is not crucial UDP is the defacto choice. If you want to know when a packet fail and you want more reliability and detection of failure, TCP is your friend.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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