A lightweight, asynchronous TcpClient with easy-to-use connection handling.
The client triggers DataReceived
, Connected
, and Disconnected
events, making it simple to manage TCP data flow. Optional TcpKeepAlive
support is available for persistent connections. Logging is customizable by passing an ILogger
instance, ensuring robust logging.
The library is thoroughly tested on all major operating systems, including Ubuntu, Windows, and macOS. A total of 14 tests are executed on each platform to ensure consistent functionality and reliability.
Operating System | Number of Tests |
---|---|
Ubuntu | 14 |
Windows | 14 |
macOS | 14 |
The package is available via NuGet
PM> install-package Nager.TcpClient
For the examples, an online service tcpbin.com
is used that returns all sent packages.
void OnDataReceived(byte[] receivedData)
{
}
using var cancellationTokenSource = new CancellationTokenSource(1000);
using var tcpClient = new TcpClient();
tcpClient.DataReceived += OnDataReceived;
await tcpClient.ConnectAsync("tcpbin.com", 4242, cancellationTokenSource.Token);
await tcpClient.SendAsync(new byte[] { 0x01, 0x0A });
await Task.Delay(400);
tcpClient.Disconnect();
tcpClient.DataReceived -= OnDataReceived;
Project | Description |
---|---|
SuperSimpleTcp | TcpServer and TcpClient (with SSL support) |
DotNetty | TcpServer and TcpClient |
SpanNetty | TcpServer and TcpClient (Modern implementation of DotNetty) |