UDP.read() - UDP_TX_PACKET_MAX_SIZE

Hello guys, I'm having fun with my Ethernet Arduino Boards. Since the boards are more than three (don't know the exact number yet), I'm trying to estabilish communication with UDP protocol and library in my local network. In particular one of this boards is the master that receives packets from every other device, then calculates some data in dependence of the packet and finally sends the result information to the devices.

My question for you is about Udp.read() function (EthernetUdp.h): I founded on the web a version of this function with this parameters in input...

Udp.read(&msg, max_msg, remoteIp, &remotePort)

Is that true? Because in the reference I can see only two versions of this function (one without arguments, the other one with packet buffer and sizeof buffer arguments).

In the case that the version I found is not correct, in the Arduino examples is possible to see this type of utilization:

Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE)

but why not:
Udp.read(packetBuffer,packetSize) ?
Final question is where I can find the size of the constant UDP_TX_PACKET_MAX_SIZE ? Or better, is possible to read the Header File EthernetUDP.h or similars?
Thanks very much for the answers.

There are actually three versions of that function. The one without arguments reads only one byte. The other two with an array pointer (either unsigned char* or char*) and the maximum length.

This is from EthernetUdp.h.

  // Read a single byte from the current packet
  virtual int read();
  // Read up to len bytes from the current packet and place them into buffer
  // Returns the number of bytes read, or 0 if none are available
  virtual int read(unsigned char* buffer, size_t len);
  // Read up to len characters from the current packet and place them into buffer
  // Returns the number of characters read, or 0 if none are available
  virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };

edit: UDP_TX_PACKET_MAX_SIZE is a define set at 24. I don't know why they call it that, because I use a packet size of 48 all the time. So does the NTP example sketch.

Again, from EthernetUdp.h.

#define UDP_TX_PACKET_MAX_SIZE 24

Thanks very much for the answer. I edited my post with another question, can you give me an explanation for that? And where I can find the EthernetUdp.h ?

I edited my answer to include that. Here it is again:

UDP_TX_PACKET_MAX_SIZE is a define set at 24. I don't know why they call it that, because I use a packet size of 48 all the time. So does the NTP example sketch.

Again, from EthernetUdp.h.

#define UDP_TX_PACKET_MAX_SIZE 24

budwhite:
In the case that the version I found is not correct, in the Arduino examples is possible to see this type of utilization:

Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE)

but why not:
Udp.read(packetBuffer,packetSize) ?

What about this part? Thanks a lot again :slight_smile:

This is basically what I use, with packetSize set to 48. Works great! :slight_smile:

Udp.read(packetBuffer,packetSize);

edit: You can use Udp.write(packetBuffer,packetSize) the same way.