{"id":19102019,"url":"https://github.com/jchristn/SuperSimpleTcp","last_synced_at":"2025-04-18T19:31:43.113Z","repository":{"id":40980030,"uuid":"159713441","full_name":"jchristn/SuperSimpleTcp","owner":"jchristn","description":"Simple wrapper for TCP client and server in C# with SSL support","archived":false,"fork":false,"pushed_at":"2024-01-16T16:07:04.000Z","size":430,"stargazers_count":445,"open_issues_count":7,"forks_count":93,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-09-18T20:52:04.236Z","etag":null,"topics":["client","messaging","mono","rpc","server","simpletcp","ssl","ssl-support","tcp","tcp-client","tcp-server"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jchristn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["jchristn"],"custom":["https://paypal.me/joelchristner"]}},"created_at":"2018-11-29T18:58:51.000Z","updated_at":"2024-09-16T01:44:14.000Z","dependencies_parsed_at":"2024-01-16T18:47:16.771Z","dependency_job_id":"35c99276-6835-433b-8b8c-d1df36ac54f4","html_url":"https://github.com/jchristn/SuperSimpleTcp","commit_stats":{"total_commits":148,"total_committers":19,"mean_commits":"7.7894736842105265","dds":0.3445945945945946,"last_synced_commit":"bf77ef05d781c0ed1c8f14ae6df77873cdf6f77d"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSuperSimpleTcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSuperSimpleTcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSuperSimpleTcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FSuperSimpleTcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchristn","download_url":"https://codeload.github.com/jchristn/SuperSimpleTcp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783208,"owners_count":17201913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","messaging","mono","rpc","server","simpletcp","ssl","ssl-support","tcp","tcp-client","tcp-server"],"created_at":"2024-11-09T03:53:38.447Z","updated_at":"2025-04-18T19:31:43.103Z","avatar_url":"https://github.com/jchristn.png","language":"C#","funding_links":["https://github.com/sponsors/jchristn","https://paypal.me/joelchristner"],"categories":["server"],"sub_categories":[],"readme":"﻿![supersimpletcp](https://github.com/jchristn/supersimpletcp/blob/master/assets/icon.ico)\n\n# SuperSimpleTcp\n\n## Simple wrapper for TCP client and server in C# with SSL support\n\n[![NuGet Version](https://img.shields.io/nuget/v/SuperSimpleTcp.svg?style=flat)](https://www.nuget.org/packages/SuperSimpleTcp/) [![NuGet](https://img.shields.io/nuget/dt/SuperSimpleTcp.svg)](https://www.nuget.org/packages/SuperSimpleTcp)    \n\nSuperSimpleTcp provides simple methods for creating your own TCP-based sockets application, enabling easy integration of connection management, sending, and receiving data.  \n\n- If you need integrated framing, please use WatsonTcp (https://github.com/jchristn/WatsonTcp)\n- If you need discrete control over the number of bytes read from or written to a socket, please use CavemanTcp (https://github.com/jchristn/CavemanTcp)\n\n**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**\n\n## New in v3.0.x\n\n- Breaking change, allocation-free receive (thank you @joreg)\n- Configurable sync vs async for firing DataReceived events (thank you @TheNybbler)\n- More configurability around certificate validation checks (thank you @ATS-CE)\n- Better catch client timeouts during TLS establishment (thank you @ATS-CE)\n- Add ```NoDelay``` to settings (thank you @huangjia2107)\n- Fix for PollSocket method, thank you @zllvm @Energiz0r @Espen-Kalhagen-Element-Logic\n- Added server-side ```NoDelay``` property in settings, thank you @QTPah\n\n## Special Thanks\n\nA special thanks to the community of people that have contributed to or otherwise improved this project!\n\n@tinohager @u1035 @cmeeren @pha3z @opnop @kopkarmecoindo @simonhaines @matt1tk @lukeacat \n@exergist @maynardsi @sector13371 @loganwoodxyz @jwfxpr @IanPNewson @EGirardi @redrabbit007 \n@eatyouroats @joreg @CetinOzdil @tautvilis @ATS-CE @TheNybbler @huangjia2107 @zllvm \n@Energiz0r @Espen-Kalhagen-Element-Logic @MarkBreedveld @QTPah @olifer @KimEoJin \n@BrandenEK @Somfic\n\n## Help or Feedback\n\nNeed help or have feedback? Please file an issue here!\n\n## Simple Examples\n\n### Server Example\n```csharp\nusing SuperSimpleTcp;\n\nvoid Main(string[] args)\n{\n  // instantiate\n  SimpleTcpServer server = new SimpleTcpServer(\"127.0.0.1:9000\");\n\n  // set events\n  server.Events.ClientConnected += ClientConnected;\n  server.Events.ClientDisconnected += ClientDisconnected;\n  server.Events.DataReceived += DataReceived;\n\n  // let's go!\n  server.Start();\n\n  // once a client has connected...\n  server.Send(\"[ClientIp:Port]\", \"Hello, world!\");\n  Console.ReadKey();\n}\n\nstatic void ClientConnected(object sender, ConnectionEventArgs e)\n{\n  Console.WriteLine($\"[{e.IpPort}] client connected\");\n}\n\nstatic void ClientDisconnected(object sender, ConnectionEventArgs e)\n{\n  Console.WriteLine($\"[{e.IpPort}] client disconnected: {e.Reason}\");\n}\n\nstatic void DataReceived(object sender, DataReceivedEventArgs e)\n{\n  Console.WriteLine($\"[{e.IpPort}]: {Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count)}\");\n}\n```\n\n### Client Example\n```csharp\nusing SuperSimpleTcp;\n\nvoid Main(string[] args)\n{\n  // instantiate\n  SimpleTcpClient client = new SimpleTcpClient(\"127.0.0.1:9000\");\n\n  // set events\n  client.Events.Connected += Connected;\n  client.Events.Disconnected += Disconnected;\n  client.Events.DataReceived += DataReceived;\n\n  // let's go!\n  client.Connect();\n\n  // once connected to the server...\n  client.Send(\"Hello, world!\");\n  Console.ReadKey();\n}\n\nstatic void Connected(object sender, ConnectionEventArgs e)\n{\n  Console.WriteLine($\"*** Server {e.IpPort} connected\");\n}\n\nstatic void Disconnected(object sender, ConnectionEventArgs e)\n{\n  Console.WriteLine($\"*** Server {e.IpPort} disconnected\"); \n}\n\nstatic void DataReceived(object sender, DataReceivedEventArgs e)\n{\n  Console.WriteLine($\"[{e.IpPort}] {Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count)}\");\n}\n```\n\n### Connect With Retries\n\nThe ```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.\n```csharp\nclient.ConnectWithRetries(10000); // try for up to 10000 milliseconds\n```\n\n### Additional Configuration Options\n\nBoth SimpleTcpClient and SimpleTcpServer have settable values for:\n\n- ```Logger``` - method to invoke to send log messages from either SimpleTcpClient or SimpleTcpServer\n- ```Settings.MutuallyAuthenticate``` - only used if SSL is enabled, demands that both client and server mutually authenticate\n- ```Settings.AcceptInvalidCertificates``` - accept and allow certificates that are invalid or cannot be validated\n- ```Keepalive``` - to enable/disable keepalives and set specific parameters (disabled by default)\n\nSimpleTcpServer also has:\n\n- ```Settings.IdleClientTimeoutSeconds``` - automatically disconnect a client if data is not received within the specified number of seconds\n\nAdditionally, 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.\n\n### Local vs External Connections\n\n**IMPORTANT**\n* If you specify ```127.0.0.1``` as the listener IP address, it will only be able to accept connections from within the local host.  \n* To accept connections from other machines:\n  * Use a specific interface IP address, or\n  * Use ```null```, ```*```, ```+```, or ```0.0.0.0``` for the listener IP address (requires admin privileges to listen on any IP address)\n* Make sure you create a permit rule on your firewall to allow inbound connections on that port\n* If you use a port number under 1024, admin privileges will be required\n\n### Testing with SSL\n\nA 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```.\n\n## Disconnection Handling\n\nThe 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:\n\n| Test case | Description | Pass/Fail |\n|---|---|---|\n| Server-side dispose | Graceful termination of all client connections | PASS |\n| Server-side client removal | Graceful termination of a single client | PASS |\n| Server-side termination | Abrupt termination due to process abort or CTRL-C | PASS |\n| Client-side dispose | Graceful termination of a client connection | PASS |\n| Client-side termination | Abrupt termination due to a process abort or CTRL-C | PASS |\n| Network interface down | Network interface disabled or cable removed | Partial (see below) |\n\nAdditionally, 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.\n\nTCP keepalives are disabled by default.  To enable them:\n```csharp\nserver.Keepalive.EnableTcpKeepAlives = true;\nserver.Keepalive.TcpKeepAliveInterval = 5;      // seconds to wait before sending subsequent keepalive\nserver.Keepalive.TcpKeepAliveTime = 5;          // seconds to wait before sending a keepalive\nserver.Keepalive.TcpKeepAliveRetryCount = 5;    // number of failed keepalive probes before terminating connection\n```\n\nSome important notes about TCP keepalives:\n\n- Keepalives only work in .NET Core and .NET Framework\n- Keepalives can be enabled on either client or server, but are implemented and enforced in the underlying operating system, and may not work as expected\n- ```Keepalive.TcpKeepAliveRetryCount``` is only applicable to .NET Core; for .NET Framework, this value is forced to 10\n- *Your mileage may vary*; please remember that these are managed by the underlying operating system and not by this library\n\n## Running under Mono\n\n.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).\n\n```\nmono --aot=nrgctx-trampolines=8096,nimt-trampolines=8096,ntrampolines=4048 --server myapp.exe\nmono --server myapp.exe\n```\n\n## Version History\n\nPlease refer to CHANGELOG.md.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2FSuperSimpleTcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchristn%2FSuperSimpleTcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2FSuperSimpleTcp/lists"}