EthernetUDP: sending a UDP package blocks a while

Background: I have four absolute rotary encoders that I read from positions from and outputs the result on the network using the EthernetUDP library.

Problem: If I start my project without the ethernet cable plugged in the UDP.beginPackage() ... UDP.endPackage() take a while (maybe 1-2 seconds). However, if I plug in the cable and then plugs it out again the package sending is fast.

I'm assuming that some kind of network magic (maybe ARP?) is done in the background and if the ethernet cable is not plugged in it will try each time?

Can I avoid this behavior? Is there a Ethernet.isPluggedIn() function that I can call?

Which version of the beginPacket() do you use? The one with an IP address or the one with a hostname?

Can I avoid this behavior? Is there a Ethernet.isPluggedIn() function that I can call?

To my knowledge the WizNet5100 chip doesn't allow to check the link state of the ethernet connection. You can lower the timeout value and decrease the retry count to be informed faster about a failing communication but you might get that information also if the network is just a bit slower.

pylon:
Which version of the beginPacket() do you use? The one with an IP address or the one with a hostname?

I use the "IP address and port" variant:

  IPAddress DESTINATION_ADDRESS(10, 125, 2, 67);
...
  UDP.beginPacket(DESTINATION_ADDRESS, 5000);

pylon:
You can lower the timeout value and decrease the retry count to be informed faster about a failing communication but you might get that information also if the network is just a bit slower.

How do I lower the time out value in this case?

I wouldn't lower the retransmission time. I would try reducing the retry count first. I think the retry count is 8 by default.

#include <utility/w5100.h>

W5100.setRetransmissionCount(1);

edit: BTW, endPacket() returns a value. If the return value is 1, the packet was sent successfully, else send failed. This means "sent to the next device". It indicates delivery to the destination only if the destination device is on the sender's localnet.

And setRetransmissionCount is a misnomer. To be technically correct, it should have been called "setAttemptCount". You can't set that to zero. If you do, it will never try to send the packet.

Works great! Thanks!