You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
usingThreeByte.LinkLib.UdpLink;// Send to a remote device on port 9000, listen on local port 9001varudp=newAsyncUdpLink("192.168.1.50",remotePort:9000,localPort:9001);// Subscribe to incoming dataudp.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 datagrambyte[]payload=System.Text.Encoding.ASCII.GetBytes("PING");udp.SendMessage(payload);// Check for queued datawhile(udp.HasData){byte[]?response=udp.GetMessage();}// Clean upudp.Dispose();
Dynamic Local Port
// Let the OS assign a local port (default behavior)varudp=newAsyncUdpLink("10.0.0.1",remotePort:8080);
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 portvarsettings=newUdpLinkSettings("10.0.0.1",remotePort:8080,localPort:8081);// With dynamic local port (default 0)varsettings=newUdpLinkSettings("10.0.0.1",remotePort:8080);