The WiFiUDP class is used send and receive UDP messages over Wi-Fi.
WiFiUDPCreates a named instance of the WiFi UDP class that can send and receive UDP messages. On AVR based boards, outgoing UDP packets are limited to 72 bytes in size currently. For non-AVR boards the limit is 1446 bytes.
WiFiUDP
none
WiFiUDP.begin()Initializes the WiFi UDP library and network settings. Starts WiFiUDP socket, listening at local port PORT.
WiFiUDP.begin(port);
port: the local port to listen on (int)
1: if successful 0: if there are no sockets available to use
WiFiUDP.available()Get the number of bytes (characters) available for reading from the buffer. This is data that's already arrived.
This function can only be successfully called after WiFiUDP.parsePacket().
available() inherits from the Stream utility class.
WiFiUDP.available()
None
the number of bytes available in the current packet 0: if parsePacket hasn't been called yet
WiFiUDP.beginPacket()Starts a connection to write UDP data to the remote connection
WiFiUDP.beginPacket(hostName, port);
WiFiUDP.beginPacket(hostIp, port);
hostName: the address of the remote host. It accepts a character string or an IPAddress
hostIp: the IP address of the remote connection (4 bytes)
port: the port of the remote connection (int)
1: if successful 0: if there was a problem with the supplied IP address or port
WiFiUDP.endPacket()Called after writing UDP data to the remote connection. It finishes off the packet and send it.
WiFiUDP.endPacket();
None
1: if the packet was sent successfully 0: if there was an error
WiFiUDP.write()Writes UDP data to the remote connection. Must be wrapped between beginPacket() and endPacket(). beginPacket() initializes the packet of data, it is not sent until endPacket() is called.
WiFiUDP.write(byte);
WiFiUDP.write(buffer, size);
byte: the outgoing byte buffer: the outgoing message size: the size of the buffer
single byte into the packet bytes size from buffer into the packet
WiFiUDP.parsePacket()It starts processing the next available incoming packet, checks for the presence of a UDP packet, and reports the size. parsePacket() must be called before reading the buffer with UDP.read().
UDP.parsePacket();
None
the size of the packet in bytes 0: if no packets are available
WiFiUDP.peek()Read a byte from the file without advancing to the next one. That is, successive calls to peek() will return the same value, as will the next call to read().
This function inherited from the Stream class. See the Stream class main page for more information.
WiFiUDP.peek()
none
b: the next byte or character -1: if none is available
WiFiUDP.read()Reads UDP data from the specified buffer. If no arguments are given, it will return the next character in the buffer.
This function can only be successfully called after WiFiUDP.parsePacket().
WiFiUDP.read();
WiFiUDP.read(buffer, len);
buffer: buffer to hold incoming packets (char*)
len: maximum size of the buffer (int)
b: the characters in the buffer (char) size: the size of the buffer -1: if no buffer is available
WiFiUDP.flush()Discard any bytes that have been written to the client but not yet read.
flush() inherits from the Stream utility class.
WiFiUDP.flush()
none
none
WiFiUDP.stop()Disconnect from the server. Release any resource being used during the UDP session.
WiFiUDP.stop()
none
none
WiFiUDP.remoteIP()Gets the IP address of the remote connection.
This function must be called after WiFiUDP.parsePacket().
WiFiUDP.remoteIP();
None
4 bytes : the IP address of the host who sent the current incoming packet
WiFiUDP.remotePort()Gets the port of the remote UDP connection.
This function must be called after UDP.parsePacket().
UDP.remotePort();
None
The port of the host who sent the current incoming packet