š” ThreeByte.LinkLib.UdpLink
Asynchronous UDP client with message queuing, configurable endpoints, and thread-safe operation.

⨠Features
| Feature |
Description |
| š” Connectionless |
Low-latency UDP datagrams ā no handshake overhead |
| š¦ Message Queuing |
Incoming datagrams queued FIFO (up to 100 messages) |
| š Thread-Safe |
All operations protected with locking |
| ā” Fully Async |
Non-blocking BeginSend / BeginReceive patterns |
| šļø Dual Port Config |
Separate remote and local port configuration |
| š Event-Driven |
Events for data arrival, errors, and enable/disable state |
š¦ Installation
dotnet add package ThreeByte.LinkLib.UdpLink
or via the NuGet Package Manager:
Install-Package ThreeByte.LinkLib.UdpLink
š Quick Start
using ThreeByte.LinkLib.UdpLink;
// Send to a remote device on port 9000, listen on local port 9001
var udp = new AsyncUdpLink("192.168.1.50", remotePort: 9000, localPort: 9001);
// Subscribe to incoming data
udp.DataReceived += (s, e) =>
{
byte[]? data = udp.GetMessage();
if (data != null)
Console.WriteLine($"Received {data.Length} bytes");
};
udp.ErrorOccurred += (s, ex) =>
Console.WriteLine($"Error: {ex.Message}");
// Send a datagram
byte[] payload = System.Text.Encoding.ASCII.GetBytes("PING");
udp.SendMessage(payload);
// Check for queued data
while (udp.HasData)
{
byte[]? response = udp.GetMessage();
}
// Clean up
udp.Dispose();
Dynamic Local Port
// Let the OS assign a local port (default behavior)
var udp = new AsyncUdpLink("10.0.0.1", remotePort: 8080);
š API Reference
AsyncUdpLink
Constructors
AsyncUdpLink(string address, int remotePort, int localPort = 0, bool enabled = true)
AsyncUdpLink(UdpLinkSettings settings, bool enabled = true)
Properties
| Property |
Type |
Description |
IsEnabled |
bool |
Whether the link is actively receiving |
Address |
string |
Remote host address |
Port |
int |
Remote port number |
HasData |
bool |
Whether there are queued incoming datagrams |
Methods
| Method |
Returns |
Description |
SendMessage(byte[]) |
void |
Sends a byte array datagram to the remote endpoint |
GetMessage() |
byte[]? |
Dequeues the next incoming datagram (FIFO) |
SetEnabled(bool) |
void |
Starts or stops the receive loop |
Dispose() |
void |
Releases the UDP socket and all resources |
Events
| Event |
Args |
Description |
IsEnabledChanged |
bool |
Fires when enabled state changes |
ErrorOccurred |
Exception |
Fires on communication errors |
DataReceived |
EventArgs |
Fires when a datagram arrives |
š§ Configuration
Use UdpLinkSettings for structured configuration:
// With explicit local port
var settings = new UdpLinkSettings("10.0.0.1", remotePort: 8080, localPort: 8081);
// With dynamic local port (default 0)
var settings = new UdpLinkSettings("10.0.0.1", remotePort: 8080);
| Property |
Type |
Description |
Address |
string |
Remote host address |
RemotePort |
int |
Remote port to send to |
LocalPort |
int |
Local port to bind (0 = OS-assigned) |
šļø Architecture
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā AsyncUdpLink ā
ā ā
ā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāāāā ā
ā ā Send (Async) ā ā Receive (Async) ā ā
ā ā ā Remote:Port ā ā ā Local:Port ā ā
ā āāāāāāāā¬āāāāāāāā āāāāāāāāāā¬āāāāāāāāāā ā
ā ā ā ā
ā ā¼ ā¼ ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā Thread-Safe Message Queue ā ā
ā ā (FIFO, max 100) ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā ā
ā ā¼ ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
ā ā Event Dispatch (Data / Error) ā ā
ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š” TCP vs UDP ā When to Use This Package
| Scenario |
Use |
| Reliable, ordered data transfer |
ThreeByte.LinkLib.TcpLink |
| Low-latency, fire-and-forget messaging |
ThreeByte.LinkLib.UdpLink ā
|
| Broadcast / multicast discovery |
ThreeByte.LinkLib.UdpLink ā
|
| Streaming sensor data |
ThreeByte.LinkLib.UdpLink ā
|
| Command-response protocols |
ThreeByte.LinkLib.TcpLink |
šÆ Platform Support
| Platform |
Supported |
| .NET 10.0 |
ā
|
| .NET Standard 2.1 |
ā
|
| .NET Standard 2.0 |
ā
|
| Windows |
ā
|
| Linux |
ā
|
| macOS |
ā
|
š License
Part of the ThreeByte.LinkLib family of communication libraries.