35 udp.onPacket([&](AsyncUDPPacket packet) {
38 result.
peer.
port = packet.remotePort();
41 result.
data.
copyFrom((
const char*)packet.data(), packet.length());
44 bool ok =
queue.enqueue(result);
47 "UDPAsyncService::enqueue failed: queue full, packet "
48 "%d bytes, queueSize=%d",
49 packet.length(), (
int)
queue.size());
57 udp.onPacket([&](AsyncUDPPacket packet) {
60 result.
peer.
port = packet.remotePort();
63 result.
data.
copyFrom((
const char*)packet.data(), packet.length());
66 bool ok =
queue.enqueue(result);
69 "UDPAsyncService::enqueue failed: multicast queue "
70 "full, packet %d bytes, queueSize=%d",
71 packet.length(), (
int)
queue.size());
74 "UDPAsyncService::receive: received %d bytes",
81 bool send(uint8_t* data,
int len) {
return send(
peer, data, len); }
94 queue.dequeue(result);
Abstract Interface for UDP API.
Definition: IUDPService.h:33
FIFO Queue which is based on a List.
Definition: Queue.h:14
void copyFrom(const char *source, int len)
Copy from raw buffer with length.
Definition: Str.h:60
Access to UDP functionality: sending and receiving of data using the Async API of the ESP32.
Definition: UDPAsyncService.h:22
IPAddressAndPort peer
Definition: UDPAsyncService.h:100
bool begin(IPAddressAndPort addr)
Initialize UDP service on specified address and port.
Definition: UDPAsyncService.h:30
AsyncUDP udp
Definition: UDPAsyncService.h:99
Queue< RequestData > queue
Definition: UDPAsyncService.h:104
bool send(IPAddressAndPort addr, uint8_t *data, int len)
Send data to specified address and port.
Definition: UDPAsyncService.h:83
RequestData receive()
Receive incoming UDP data and peer information.
Definition: UDPAsyncService.h:92
bool begin(int port)
Initialize UDP service on specified port.
Definition: UDPAsyncService.h:24
bool send(uint8_t *data, int len)
Send data to the default destination.
Definition: UDPAsyncService.h:81
Definition: Allocator.h:13
IP Adress including Port information.
Definition: IPAddressAndPort.h:20
const char * toString()
Definition: IPAddressAndPort.h:26
int port
Definition: IPAddressAndPort.h:24
IPAddress address
Definition: IPAddressAndPort.h:23
Provides information of the received UDP which consists of the (xml) data and the peer address and po...
Definition: IUDPService.h:22
IPAddressAndPort peer
Definition: IUDPService.h:24
Str data
Definition: IUDPService.h:23