easyUDP

UDP is an excellent protocol for sending messages between nodes in a system with Ethernet or Wifi. It’s speed and behavior on a modern PC’s allows in the region of 100,000 messages per sec, which should be sufficient for most applications.To make a Connection you only need two end-Points of which one need to have a known (fixed) address so the other cand send to it. The receiver get the sender address so it can send back. Sending is also fire & forget as UDP will send regardless wherever the receiver is there or not.

To create a client/server is equally simple. You simple create one client on a fixed address and the the others can contact this.

The true power of UDP is however that it is a “mail-box” on Ethernet that anyone can send to. You can send to any UDP port and receive from any UDP port. UDP bind to the local ip-address and port you use for sending, but it is connectionless so it’s not affected if the receiver drops down, reconnect or simply is not there.

easyUDP is only a thin wrapper on top of UDP to provide a standard, easy, event driven interface. To use the interface you need to do 3 Things

  1. Decide what socket to use and Open the connection. This can be fixed or you can let the computers UDP stack decide automatically. To send a message somewhere you need to know that address, so at least one of the end-points in a UDP connection need a kown address. Address here is ip-address and port number. One concern on modern networks is firewalls as the ports must be opened through firewalls.
  2. Send messages. One UDP connection can send to multiple other UDP connections by setting remote ip-address and port. But, sending here is fire & forget. UDP will send the message intact, but it gives no guarantee that anyone receive the message or what sequence messages arrives in. Sequence will be intact on a single network, but on a more complex network you might experience that packages uses different paths and arrive in a different order. Your protocol using UDP need to handle this.
  3. Receive messages. The technique I use it to establish a reader thread that call back for every message received. As you receive you also need to grab the sender address so you know where to respond back to.

UDP is very lightweight and you need to add you own protocol to maintain sequence and ack messages etc. But, UDP will maintain message integrity since the packet you send is 1:1 with what is received on the other side. The lower interface of easyUDP is different from platform to platform. I currently use a test implementation in C# on Windows that obviously will have only design and interface in common with one in C++ or one on a STM32. UDP/TCP already have a “standard” socket interface, but easyUDP uses a simpler approach of Open(), Close(), Send() and OnMessage().

UDP packets consist of UDP + IP Header + payload. easyUDP will in addition add it’s own little header to support streams. Basically we pack multiple easyIPC messages into the same UDP packet using the standard easyIPC format per Message.

Leave a Reply