There is an error in the ethernet library UDP section. The UDP.begin(localPort) call documentation shows there is no return value. That is not correct.
The UDP.begin(localPort) call returns 1 on success, and 0 if no socket is available.
This is from EthernetUdp.h
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
and this from EthernetUdp.cpp
/* Start EthernetUDP socket, listening at local port PORT */
uint8_t EthernetUDP::begin(uint16_t port) {
if (_sock != MAX_SOCK_NUM)
return 0;
for (int i = 0; i < MAX_SOCK_NUM; i++) {
uint8_t s = W5100.readSnSR(i);
if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT) {
_sock = i;
break;
}
}
if (_sock == MAX_SOCK_NUM)
return 0;
_port = port;
_remaining = 0;
socket(_sock, SnMR::UDP, _port, 0);
return 1;
}
An error report was sent to webmaster@arduino.cc also.
I know there is a procedure you must go through, but it seems to take a long time for error corrections that are obvious once the change request gets to Github. This was Arduino library code with an obvious error and solution.