Syntax
class LUDP : public UDP;
ContentsIndex
PreviousUpNext
LUDP Class
Members | Example
Syntax
class LUDP : public UDP;
Description

LUDP Class 

LUDP is the base implementation of LWiFiUDP and LGPRSUDP. You should not use LUDP instances directly. Instead, declare instances of LWiFiUDP or LGPRSUDP and use them to perform UDP socket operations. 

Unlike LTcpClient and LTcpServer, a LUDP instance can send to and receive from multiple addresses. To achieve this, beginPacket() should be called first to assign remote address and port, followed by write() and finally endPacket(). Receiving packets works in a similar way. parsePacket() should be called first. After parsePacket() returns non-zero value, methods read(), available(), remoteIP() and remotePort() becomes meaningful. Each call to parsePacket() method starts the processing of a new incoming packet, which may have different retrun values from methods like remoteIP() and remotePort().

Example
    LWiFi.begin();
    LWiFiUDP u;
    u.begin(1234);  // host UDP port on 1234
    u.beginPacket(IPAddress(127.0.0.1), 123);  // start sending UDP datagram to 127.0.0.1 port 123
    u.write(0);  // the content is a single byte of value 0
    u.endPacket();  // actually send the packet
Class Hierarchy
File

LUdp.h

Group
Methods
Method 
Description 
Destructor. LUDP will close resources when it is destroyed. 
Number of remaining bytes in the current packet. Only meaningful after parsePacket() returns non-zero. 
Initializes UDP function, and start listening on specified local port. 
Start constructing an UDP datagrams to a remote host specified by IP address and port. Call write() subsequently to construct the datagram content. Then call endPacket() to actually send it. 
Start constructing an UDP datagrams to a remote host specified by URL address and port. Call write() subsequently to construct the datagram content. Then call endPacket() to actually send it. 
Send the datagram after calling beginPacket() and write(). 
Stop processing current packet. 
LUDP 
Constructor. LUDP cannot be instantiated directly. Use LWiFiUDP or LGPRSUDP instead. 
Check if there are incoming UDP datagrams. read() should be then used to actually read the data from packet. 
peek 
return the value of next available byte from current packet. The byte remains in the packet. 
read 
Read 1 byte from current packet after calling parsePacket(); 
read 
Read up to len bytes from current packet after calling parsePacket(); 
retrieve the sender IP address of the current packet started by parsePacket() 
retrieve the sender port of the current packet started by parsePacket() 
stop 
Stop listening for UDP datagram and uninitializes UDP module. 
Append 1 single byte into the datagram 
Append a buffer into the datagram.