Communication Between Java Program and an Arduino over Ethernet using UDP


I’m working on a project that requires me to send a JSON object from a Java program over Ethernet to an Arduino where I will then parse it and print on a display I have wired up. I have the Java program coded which is sending the string as a DatagramPacket using UDP but am having some trouble with the Arduino code (which should receive the string using UDP). I am using the <Ethernet.h> library for Ethernet connectivity on my Arduino. I found a couple of “Ethercard.h udp listener” examples online but they don’t seem to be working for me and I don’t really understand them. Any help would be appreciated.


Could you be a be a bit more specific about your setup? Which Arduino do you have and which library and example did you use?

I do not have an Arduino with Ethernet but I have some with WiFi. I loaded the WiFiUdpSendReceiveString example from the WiFi101 library and send myself a JSON object with node-red from Raspberry Pi. My board received the UDP package and returned one which I received on my Raspberry Pi.

The same example is available for Ethernet (File -> Examples ->Ethernet). Its just called UDPSendReceiveString. Did you see this one?

Also did you try any other Ethernet examples to make sure the board connects to your network and can do something? e.g. LinkStatus or WebServer.