#include <EthernetUdp.h>


Public Member Functions | |
| EthernetUDP () | |
| Constructs an EthernetUDP object without opening a socket. | |
| virtual uint8_t | begin (uint16_t) |
| Opens a unicast UDP socket on a local port. | |
| virtual uint8_t | begin (IPAddress, uint16_t, bool multicast=false) |
| Opens a UDP socket bound to a local address and port. | |
| virtual uint8_t | beginMulticast (IPAddress, uint16_t) |
| Opens a UDP socket that joins a multicast group. | |
| virtual void | stop () |
| Closes the UDP socket. | |
| virtual int | beginPacket (IPAddress ip, uint16_t port) |
| Sets the destination for the next outgoing packet. | |
| virtual int | beginPacket (const char *host, uint16_t port) |
| Sets the destination for the next outgoing packet by host name. | |
| virtual int | endPacket () |
| Sends the data written since beginPacket() as one datagram. | |
| virtual size_t | write (uint8_t) |
| Appends one byte to the outgoing packet. | |
| virtual size_t | write (const uint8_t *buffer, size_t size) |
| Appends a block of bytes to the outgoing packet. | |
| virtual int | parsePacket () |
| Advances to the next received packet. | |
| virtual int | available () |
| Returns the number of unread bytes in the current packet. | |
| virtual int | read () |
| Reads one byte from the current packet. | |
| virtual int | read (unsigned char *buffer, size_t len) |
| Reads up to len bytes from the current packet into buffer. | |
| virtual int | read (char *buffer, size_t len) |
| Reads up to len characters from the current packet into buffer. | |
| virtual int | peek () |
| Returns the next byte of the current packet without consuming it. | |
| virtual void | flush () |
| Intended to wait for the transmit buffer to empty. | |
| virtual IPAddress | remoteIP () |
| Returns the IP address of the sender of the current packet. | |
| virtual uint16_t | remotePort () |
| Returns the port of the sender of the current packet. | |
| virtual void | onDataArrival (std::function< void()> onDataArrival_fn) |
| Registers a callback invoked when a UDP datagram arrives. | |
Protected Attributes | |
| uint16_t | _remaining |
| EthernetUDP::EthernetUDP | ( | ) |
Constructs an EthernetUDP object without opening a socket.
Call begin() or beginMulticast() to open a socket.
|
virtual |
Returns the number of unread bytes in the current packet.
Returns 0 until parsePacket() has been called.
|
virtual |
Opens a UDP socket bound to a local address and port.
Fails if this object already has an open socket. When multicast is true, the socket binds to any address and joins the multicast group ip through IGMP (when LWIP_IGMP is enabled). Otherwise it binds to ip. If the bind fails, the socket is closed. If the IGMP join fails, the socket stays open; call stop() to close it.
| ip | Local address to bind to, or the multicast group to join. |
| port | Local port to listen on. |
| multicast | true to join the multicast group ip, false for a unicast socket bound to ip. |
|
virtual |
Opens a unicast UDP socket on a local port.
The socket is bound to the address returned by Ethernet.localIP().
| port | Local port to listen on. |
|
virtual |
Opens a UDP socket that joins a multicast group.
Equivalent to begin(ip, port, true).
| ip | Multicast group address to join. |
| port | Local port to listen on. |
|
virtual |
Sets the destination for the next outgoing packet by host name.
Resolves host with a DNS query to the server returned by Ethernet.dnsServerIP(), then calls beginPacket(IPAddress, uint16_t).
| host | Host name, or a numeric address string. |
| port | Destination port. |
|
virtual |
Sets the destination for the next outgoing packet.
The address and port are stored as given and not validated. Call write() and endPacket() afterwards.
| ip | Destination IP address. |
| port | Destination port. |
|
virtual |
Sends the data written since beginPacket() as one datagram.
The buffered data is released whether or not the send succeeds.
|
virtual |
Intended to wait for the transmit buffer to empty.
Currently a no-op. Waiting for the transmit buffer is a TODO.
|
virtual |
Registers a callback invoked when a UDP datagram arrives.
Replaces any previously registered callback.
| onDataArrival_fn | Function to call when a datagram arrives. |
|
virtual |
Advances to the next received packet.
Runs the Ethernet scheduler. If a datagram is queued, records its sender for remoteIP() and remotePort() and its unread size for available() and read().
|
virtual |
Returns the next byte of the current packet without consuming it.
|
virtual |
Reads one byte from the current packet.
|
inlinevirtual |
Reads up to len characters from the current packet into buffer.
Forwards to read(unsigned char *, size_t).
| buffer | Destination buffer; must hold at least len bytes. |
| len | Maximum number of characters to read. |
|
virtual |
Reads up to len bytes from the current packet into buffer.
Reads at most the number of unread bytes in the packet.
| buffer | Destination buffer; must hold at least len bytes. |
| len | Maximum number of bytes to read. |
|
inlinevirtual |
Returns the IP address of the sender of the current packet.
The value is set by parsePacket().
|
inlinevirtual |
Returns the port of the sender of the current packet.
The value is set by parsePacket().
|
virtual |
Closes the UDP socket.
Does nothing if no socket is open.
|
virtual |
Appends a block of bytes to the outgoing packet.
Data accumulates until endPacket() sends it. On failure, the data already buffered for the packet is kept and the new bytes are not added.
| buffer | Bytes to append. |
| size | Number of bytes in buffer. |
|
virtual |
Appends one byte to the outgoing packet.
| byte | Byte to append. |
|
protected |