![]() |
VOOZH | about |
dotnet add package SuperSimpleTcp --version 3.1.0
NuGet\Install-Package SuperSimpleTcp -Version 3.1.0
<PackageReference Include="SuperSimpleTcp" Version="3.1.0" />
<PackageVersion Include="SuperSimpleTcp" Version="3.1.0" />Directory.Packages.props
<PackageReference Include="SuperSimpleTcp" />Project file
paket add SuperSimpleTcp --version 3.1.0
#r "nuget: SuperSimpleTcp, 3.1.0"
#:package SuperSimpleTcp@3.1.0
#addin nuget:?package=SuperSimpleTcp&version=3.1.0Install as a Cake Addin
#tool nuget:?package=SuperSimpleTcp&version=3.1.0Install as a Cake Tool
SuperSimpleTcp provides simple methods for creating your own TCP-based sockets application, enabling easy integration of connection management, sending, and receiving data.
I would highly encourage you to fully understand what message framing is and why it's important before using this library: https://blog.stephencleary.com/2009/04/message-framing.html
RunBenchmarks.bat runner that writes timestamped summaries under benchmarks/A special thanks to the community of people that have contributed to or otherwise improved this project!
@tinohager @u1035 @cmeeren @pha3z @opnop @kopkarmecoindo @simonhaines @matt1tk @lukeacat @exergist @maynardsi @sector13371 @loganwoodxyz @jwfxpr @IanPNewson @EGirardi @redrabbit007 @eatyouroats @joreg @CetinOzdil @tautvilis @ATS-CE @TheNybbler @huangjia2107 @zllvm @Energiz0r @Espen-Kalhagen-Element-Logic @MarkBreedveld @QTPah @olifer @KimEoJin @BrandenEK @Somfic @kszaq @rstelmokaitis @GoannaGuy @Sympatron
Need help or have feedback? Please file an issue here!
using SuperSimpleTcp;
void Main(string[] args)
{
// instantiate
SimpleTcpServer server = new SimpleTcpServer("127.0.0.1:9000");
// set events
server.Events.ClientConnected += ClientConnected;
server.Events.ClientDisconnected += ClientDisconnected;
server.Events.DataReceived += DataReceived;
// let's go!
server.Start();
// once a client has connected...
server.Send("[ClientIp:Port]", "Hello, world!");
Console.ReadKey();
}
static void ClientConnected(object sender, ConnectionEventArgs e)
{
Console.WriteLine($"[{e.IpPort}] client connected");
}
static void ClientDisconnected(object sender, ConnectionEventArgs e)
{
Console.WriteLine($"[{e.IpPort}] client disconnected: {e.Reason}");
}
static void DataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine($"[{e.IpPort}]: {Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count)}");
}
using SuperSimpleTcp;
void Main(string[] args)
{
// instantiate
SimpleTcpClient client = new SimpleTcpClient("127.0.0.1:9000");
// set events
client.Events.Connected += Connected;
client.Events.Disconnected += Disconnected;
client.Events.DataReceived += DataReceived;
// let's go!
client.Connect();
// once connected to the server...
client.Send("Hello, world!");
Console.ReadKey();
}
static void Connected(object sender, ConnectionEventArgs e)
{
Console.WriteLine($"*** Server {e.IpPort} connected");
}
static void Disconnected(object sender, ConnectionEventArgs e)
{
Console.WriteLine($"*** Server {e.IpPort} disconnected");
}
static void DataReceived(object sender, DataReceivedEventArgs e)
{
Console.WriteLine($"[{e.IpPort}] {Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count)}");
}
The ConnectWithRetries method on SimpleTcpClient can be used instead of Connect to continually attempt to establish connections with the server for a given period of time. Like Connect, ConnectWithRetries will throw a TimeoutException if it is unable to successfully establish a connection.
client.ConnectWithRetries(10000); // try for up to 10000 milliseconds
Both SimpleTcpClient and SimpleTcpServer have settable values for:
Logger - method to invoke to send log messages from either SimpleTcpClient or SimpleTcpServerSettings.MutuallyAuthenticate - only used if SSL is enabled, demands that both client and server mutually authenticateSettings.AcceptInvalidCertificates - accept and allow certificates that are invalid or cannot be validatedKeepalive - to enable/disable keepalives and set specific parameters (disabled by default)SimpleTcpServer also has:
Settings.IdleClientTimeoutMs - automatically disconnect a client if data is not received within the specified number of millisecondsAdditionally, both SimpleTcpClient and SimpleTcpServer offer a statistics object under SimpleTcpClient.Statistics and SimpleTcpServer.Statistics. These values (other than start time and uptime) can be reset using the Statistics.Reset() API.
IMPORTANT
127.0.0.1 as the listener IP address, it will only be able to accept connections from within the local host.null, *, +, or 0.0.0.0 for the listener IP address (requires admin privileges to listen on any IP address)A certificate named simpletcp.pfx is provided for simple testing. It should not expire for a really long time. It's a self-signed certificate and you should NOT use it in production. Its export password is simpletcp.
Run RunBenchmarks.bat from the repository root to build src/Test.PerformanceBenchmark and write a timestamped benchmark summary to benchmarks/Benchmark-YYYYMMDD-HHMMSS.txt.
The project TcpTest (https://github.com/jchristn/TcpTest) was built specifically to provide a reference for SuperSimpleTcp to handle a variety of disconnection scenarios. The disconnection tests for which SimpleTcp is evaluated include:
| Test case | Description | Pass/Fail |
|---|---|---|
| Server-side dispose | Graceful termination of all client connections | PASS |
| Server-side client removal | Graceful termination of a single client | PASS |
| Server-side termination | Abrupt termination due to process abort or CTRL-C | PASS |
| Client-side dispose | Graceful termination of a client connection | PASS |
| Client-side termination | Abrupt termination due to a process abort or CTRL-C | PASS |
| Network interface down | Network interface disabled or cable removed | Partial (see below) |
Additionally, as of v2.1.0, support for TCP keepalives has been added to SimpleTcp, primarily to address the issue of a network interface being shut down, the cable unplugged, or the media otherwise becoming unavailable. It is important to note that keepalives are supported in .NET Core and .NET Framework, but NOT .NET Standard. As of this release, .NET Standard provides no facilities for TCP keepalives.
TCP keepalives are disabled by default. To enable them:
server.Keepalive.EnableTcpKeepAlives = true;
server.Keepalive.TcpKeepAliveInterval = 5; // seconds to wait before sending subsequent keepalive
server.Keepalive.TcpKeepAliveTime = 5; // seconds to wait before sending a keepalive
server.Keepalive.TcpKeepAliveRetryCount = 5; // number of failed keepalive probes before terminating connection
Some important notes about TCP keepalives:
Keepalive.TcpKeepAliveRetryCount is only applicable to .NET Core; for .NET Framework, this value is forced to 10.NET Core is the preferred environment for cross-platform deployment on Windows, Linux, and Mac. For those that use Mono, SimpleTcp should work well in Mono environments. It is recommended that you execute the containing EXE using --server and after using the Mono Ahead-of-Time Compiler (AOT).
mono --aot=nrgctx-trampolines=8096,nimt-trampolines=8096,ntrampolines=4048 --server myapp.exe
mono --server myapp.exe
Please refer to CHANGELOG.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 is compatible. net462 net462 is compatible. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on SuperSimpleTcp:
| Package | Downloads |
|---|---|
|
ESCPOS_NET
.NET Standard 2.0 Implementation of ESC/POS command generation and integration with thermal printers. Allows creating receipts with all common functionality supported. |
|
|
FrameworkOfAliveApplication.StandardBase.Utility
Utility library |
|
|
Vinci.Protocols.Communication
Package Description |
|
|
Vinci.Protocols.Iec60875_104
Package Description |
|
|
VL.IO.TCP
TCP for VL |
Showing the top 2 popular GitHub repositories that depend on SuperSimpleTcp:
| Repository | Stars |
|---|---|
|
lukevp/ESC-POS-.NET
Efficient, Easy to Use Thermal Printing & POS (Windows/Linux/OSX, WiFi/BT/USB/Ethernet)
|
|
|
Portalum/Portalum.Zvt
A .NET Zvt Library for Payment Terminals (C#)
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.0 | 1,653 | 5/20/2026 |
| 3.0.23 | 9,558 | 3/4/2026 |
| 3.0.22 | 948 | 3/1/2026 |
| 3.0.21 | 3,894 | 2/12/2026 |
| 3.0.20 | 12,990 | 11/3/2025 |
| 3.0.19 | 696 | 10/24/2025 |
| 3.0.18 | 251 | 10/24/2025 |
| 3.0.17 | 297,979 | 12/23/2024 |
| 3.0.14 | 87,280 | 1/16/2024 |
| 3.0.13 | 27,579 | 8/25/2023 |
| 3.0.12 | 8,192 | 7/13/2023 |
| 3.0.11 | 3,040 | 7/4/2023 |
| 3.0.10 | 75,931 | 2/24/2023 |
| 3.0.9 | 1,071 | 2/24/2023 |
| 3.0.8 | 1,037 | 2/24/2023 |
| 3.0.7 | 7,724 | 1/18/2023 |
| 3.0.6 | 13,449 | 1/2/2023 |
| 3.0.5 | 15,145 | 11/1/2022 |
| 3.0.4 | 1,487 | 10/28/2022 |
| 3.0.3 | 1,149 | 10/28/2022 |
Performance/connectivity refactor, Touchstone test harnesses, and benchmark runner