Skip to content

Latest commit

 

History

History
57 lines (40 loc) · 2.1 KB

README.md

File metadata and controls

57 lines (40 loc) · 2.1 KB

Nager.TcpClient

Nager TcpClient

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.



Comprehensive Test Coverage Across Major Operating Systems

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

How can I use it?

The package is available via NuGet

PM> install-package Nager.TcpClient

Examples of use

For the examples, an online service tcpbin.com is used that returns all sent packages.

Simple example send and receive data

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;

Other projects in the .NET enviorment

Project Description
SuperSimpleTcp TcpServer and TcpClient (with SSL support)
DotNetty TcpServer and TcpClient
SpanNetty TcpServer and TcpClient (Modern implementation of DotNetty)