Hi,
Tommaso, in the Italian forum, is doing some experiment using the UDP lib.
He found out that if at least one of the receiver is invalid (non existent, offline, etc..) the time for sending a message is 10 time slower...
test skecth:
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <Udp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,202 };
unsigned int localPort = 8888; // local port to listen on
byte remoteIp[] = { 192,168,0,201 };
byte remoteIp2[] = {192,168,0,203 };
unsigned int remotePort = 8888; // holds received packet's originating port
unsigned int remotePort2 = 8889;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char invio[3];
int stati = 0;
void setup() {
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
}
void loop() {
stati = 10;
itoa(stati,invio,10);
Serial.print("Ho inviato");
Serial.println(invio);
Udp.sendPacket( invio, remoteIp, remotePort);
Udp.sendPacket( invio, remoteIp2, remotePort2);
delay(200);
}
I have take a look at what is going on...
and i think the error is in Socket.cpp:
/**
* @brief This function is an application I/F function which is used to send the data for other then TCP mode.
* Unlike TCP transmission, The peer's destination address and the port is needed.
*
* @return This function return send data size for success else -1.
*/
uint16_t sendto(SOCKET s, const uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
{
uint16_t ret=0;
if (len > W5100.SSIZE) ret = W5100.SSIZE; // check size not to exceed MAX size.
else ret = len;
if
(
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
((port == 0x00)) ||(ret == 0)
)
{
/* +2008.01 [bj] : added return value */
ret = 0;
}
else
{
W5100.writeSnDIPR(s, addr);
W5100.writeSnDPORT(s, port);
// copy data
W5100.send_data_processing(s, (uint8_t *)buf, ret);
W5100.execCmdSn(s, Sock_SEND);
/* +2008.01 bj */
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
{
/* +2008.01 [bj]: clear interrupt */
W5100.writeSnIR(s, (SnIR::SEND_OK | SnIR::TIMEOUT)); /* clear SEND_OK & TIMEOUT */
return 0;
}
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);
}
return ret;
}
as you can see there is a while that wait for response or timeout.. but this is wrong in UDP, isn't it?