UDPSendReceiveServer
A simple bidirectional UDP socket pair: one socket for sending to a fixed target address/port, and a separate socket bound to a local port for asynchronously receiving incoming datagrams on a background thread.
Every fallible operation returns a Result; the only exception is close, which must return Unit to satisfy AutoCloseable and therefore logs its failures instead. Use shutDown when you want the outcome as a value.
Maximum payload
A received datagram is decoded whole up to 65507 bytes (the maximum UDP payload over IPv4, and the default receiveBufferBytes). A datagram larger than the configured buffer is delivered truncated, not rejected (a WARN is logged). For real-network use keep frames under the path MTU (~1200 bytes) to avoid IP fragmentation and the loss it brings.
Parameters
the address messages sent via send are delivered to
the port on targetAddress that messages sent via send are delivered to
the local port this server binds to receive incoming datagrams
size of the datagram receive buffer, 512..65507; defaults to 65507
No DeliveryMode / UdpChannel surface, by design
This type deliberately has no reliable-ordered channel, and never will. It is a standalone two-socket primitive (sendSocket plus a separately-bound listenSocket) with no handshake and no registration - there is no Connection here, and therefore no registered peer to key a ReliableChannelEngine or a retransmit schedule to. A reliable channel needs both; giving this type one would mean standing up a second, parallel reliability stack for a primitive nobody builds a session on. See docs/webtools-udp-architecture.md for the full reasoning.
Constructors
Types
Functions
AutoCloseable entry point, so this server can be used with use { }. Delegates to shutDown and discards the outcome - the interface fixes the return type as Unit, so failures are only logged. Call shutDown directly if you need to react to them.
Stops listening, closes both the send and listen sockets, and waits (up to LISTENER_JOIN_TIMEOUT_MILLIS) for the listener thread to terminate.
Starts a background thread that blocks on listenSocket's receive, decoding each incoming datagram as a UTF-8 string and passing it to onMessage along with the sender's address.
Signals the background listener loop to stop and closes listenSocket, interrupting any in-progress blocking receive() call.