{"id":31282222,"url":"https://github.com/akon47/simpletcp","last_synced_at":"2025-09-24T03:44:35.826Z","repository":{"id":47366825,"uuid":"399384612","full_name":"akon47/SimpleTcp","owner":"akon47","description":"📡 A simple-to-use TCP server and client library.","archived":false,"fork":false,"pushed_at":"2021-09-02T04:10:11.000Z","size":196,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-23T12:00:57.057Z","etag":null,"topics":["client","csharp-library","http-server","mono","nuget-package","tcp","tcp-socket"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/SimpleTcpLib/","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/akon47.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-24T08:06:19.000Z","updated_at":"2024-10-24T12:20:51.000Z","dependencies_parsed_at":"2022-09-11T02:11:01.275Z","dependency_job_id":null,"html_url":"https://github.com/akon47/SimpleTcp","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/akon47/SimpleTcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akon47%2FSimpleTcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akon47%2FSimpleTcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akon47%2FSimpleTcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akon47%2FSimpleTcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akon47","download_url":"https://codeload.github.com/akon47/SimpleTcp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akon47%2FSimpleTcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276689016,"owners_count":25686611,"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","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","csharp-library","http-server","mono","nuget-package","tcp","tcp-socket"],"created_at":"2025-09-24T03:44:30.430Z","updated_at":"2025-09-24T03:44:35.811Z","avatar_url":"https://github.com/akon47.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![logo](https://raw.githubusercontent.com/akon47/SimpleTcp/master/SimpleTcp/logo.png)\n\n# SimpleTcp\n\u003cp\u003e\n    \u003cimg alt=\"Hits\" src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fakon47%2FSimpleTcp\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false\" /\u003e\n  \u003cimg alt=\"MIT license\" src=\"https://img.shields.io/badge/License-MIT-green.svg\"\u003e\n  \u003cimg alt=\"Nuget version\" src=\"https://img.shields.io/nuget/v/SimpleTcpLib\"\u003e\n  \u003cimg alt=\"Nuget downloads\" src=\"https://img.shields.io/nuget/dt/SimpleTcpLib\"\u003e\n  \u003cimg alt=\"GitHub starts\" src=\"https://img.shields.io/github/stars/akon47/SimpleTcp\"\u003e\n\u003c/p\u003e\nA simple-to-use TCP server and client library.   \n\n## 🎨 Features\n- Asynchronous servers and clients that are very easy to use.\n- PacketTcpServer that ensures reception without truncating the size of the data sent.\n- HTTP server that is very simple to use.\n\n## 📃 Usage\n\n### Start Tcp Server\n```csharp\nRawTcpServer tcpServer = new RawTcpServer();\ntcpServer.Start(5000);\n```\n\n### Can use Event Handlers\n```csharp\nRawTcpServer tcpServer = new RawTcpServer();\ntcpServer.ClientConnected += ClientConnected;\ntcpServer.ClientDisconnected += ClientDisconnected;\ntcpServer.DataReceived += DataReceived;\n```\n\n### Get connected clinets\n```csharp\ntcpServer.Clients\n```\n\n### Send data to client\n```csharp\ntcpServer.Clients[0].Write(buffer, 0, buffer.Length);\n```\n\n### Send data to connected all clients\n```csharp\ntcpServer.WriteToAllClients(buffer, 0, buffer.Length);\n```\n---\n### Connect to Tcp Server\n```csharp\nRawTcpClient tcpClient = new RawTcpClient();\ntcpClient.Connect(\"127.0.0.1\", 5000);\n```\n\n### Can use Event Handlers\n```csharp\nRawTcpClient tcpClient = new RawTcpClient();\ntcpClient.Connected += Connected;\ntcpClient.Disconnected += Disconnected;\ntcpClient.DataReceived += DataReceived;\n```\n\n### Send data to server\n```csharp\ntcpClient.Write(buffer, 0, buffer.Length);\n```\n---\n### Start Simple Http Server\nSee the example project for details.\n```csharp\nHttpServer httpServer = new HttpServer();\nhttpServer.HttpRequest += (sender, e) =\u003e\n{\n    return new HttpResponse(HttpStatusCode.OK); \n};\nhttpServer.Start(); // default start port is 80\n```\n\n## 🐾 Examples\n\n\u003cdetails\u003e\n\u003csummary style=\"font-Weight : bold; font-size : 30px; color : #E43914;\" \u003eEcho Server / Client\u003c/summary\u003e\n  \n### Echo Server\n```csharp\nstatic void Main(string[] args)\n{\n    using (RawTcpServer tcpServer = new RawTcpServer())\n    {\n        tcpServer.ClientConnected += (sender, e) =\u003e\n            Console.WriteLine($\"[{e}]: Connected\"); // new client connected\n        tcpServer.ClientDisconnected += (sender, e) =\u003e\n            Console.WriteLine($\"[{e}]: Disconnected\"); // client disconnected\n        tcpServer.DataReceived += (sender, e) =\u003e\n        {\n            byte[] readBytes = e.Client.ReadExisting(); // read all data\n            string dataString = readBytes.Aggregate( // data to hex string\n                new StringBuilder(32),\n                (stringBuilder, data) =\u003e stringBuilder.Append($\" 0x{data.ToString(\"X2\")}\")\n                ).ToString().Trim();\n\n            Console.WriteLine($\"[{e.Client}]: {dataString}\");\n\n            e.Client.Write(readBytes, 0, readBytes.Length); // return same data\n        };\n\n        try\n        {\n            tcpServer.Start(5000);\n            Console.WriteLine(\"Listening for connections...\");\n        }\n        catch (Exception ex)\n        {\n            Console.WriteLine(ex);\n        }\n\n        Console.ReadLine();\n    }\n}\n```\n\n### Echo Client\n```csharp\nstatic void Main(string[] args)\n{\n    using (RawTcpClient tcpClient = new RawTcpClient())\n    {\n        tcpClient.Connected += (sender, e) =\u003e\n            Console.WriteLine($\"Connect to [{e.RemoteEndPoint}]\");\n        tcpClient.Disconnected += (sender, e) =\u003e\n            Console.WriteLine($\"{Environment.NewLine}Disconnected from [{e.RemoteEndPoint}]\");\n        tcpClient.DataReceived += (sender, e) =\u003e\n        {\n            if (sender is RawTcpClient rawTcpClient)\n            {\n                byte[] readBytes = rawTcpClient.ReadExisting(); // read all data\n                Console.WriteLine($\"DataReceived: {Encoding.ASCII.GetString(readBytes)}\");\n            }\n        };\n\n        try\n        {\n            tcpClient.Connect(\"127.0.0.1\", 5000);\n\n            while (true)\n            {\n                string line = Console.ReadLine();\n                byte[] buffer = Encoding.ASCII.GetBytes(line);\n                tcpClient.Write(buffer, 0, buffer.Length);\n            }\n        }\n        catch (Exception ex)\n        {\n            Console.WriteLine(ex);\n            Console.ReadLine();\n        }\n    }\n}\n```\n  \n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary style=\"font-Weight : bold; font-size : 30px; color : #E43914;\" \u003ePacket Echo Server / Client\u003c/summary\u003e\n  \n### Packet Echo Server\nThe size of the received data is received without being cut off.\n```csharp\nstatic void Main(string[] args)\n{\n  using (PacketTcpServer tcpServer = new PacketTcpServer())\n  {\n      tcpServer.ClientConnected += (sender, e) =\u003e\n          Console.WriteLine($\"[{e}]: Connected\"); // new client connected\n      tcpServer.ClientDisconnected += (sender, e) =\u003e\n          Console.WriteLine($\"[{e}]: Disconnected\"); // client disconnected\n      tcpServer.PacketReceived += (sender, e) =\u003e\n      {\n          if (sender is PacketTcpServer packetTcpServer)\n          {\n              Console.WriteLine($\"[{e.Packet.IPEndPoint}]: PacketReceived (PacketLength: {e.Packet.PacketData.Length})\");\n              packetTcpServer.WritePacket(e.Packet.TcpClient, e.Packet.PacketData); // return same packet\n          }\n      };\n\n      try\n      {\n          tcpServer.Start(5000);\n          Console.WriteLine(\"Listening for connections...\");\n      }\n      catch (Exception ex)\n      {\n          Console.WriteLine(ex);\n      }\n\n      Console.ReadLine();\n  }\n}\n```\n\n### Packet Echo Client\n```csharp\nstatic void Main(string[] args)\n{\n    using (PacketTcpClient tcpClient = new PacketTcpClient())\n    {\n        tcpClient.Connected += (sender, e) =\u003e\n            Console.WriteLine($\"Connect to [{e.RemoteEndPoint}]\");\n        tcpClient.Disconnected += (sender, e) =\u003e\n            Console.WriteLine($\"{Environment.NewLine}Disconnected from [{e.RemoteEndPoint}]\");\n        tcpClient.PacketReceived += (sender, e) =\u003e\n        {\n            Console.WriteLine($\"PacketReceived: (PacketLength: {e.PacketData.Length})\");\n        };\n\n        try\n        {\n            tcpClient.Connect(\"127.0.0.1\", 5000);\n\n            tcpClient.WritePacket(new byte[1024]); // send 1024 bytes\n            tcpClient.WritePacket(new byte[1024 * 1024]); // send 1024 * 1024 bytes\n            tcpClient.WritePacket(new byte[1024 * 1024 * 10]); // send 1024 * 1024 * 10 bytes\n\n            Console.ReadLine();\n\n            tcpClient.Disconnect();\n        }\n        catch (Exception ex)\n        {\n            Console.WriteLine(ex);\n        }\n\n        Console.ReadLine();\n    }\n}\n```\n\n![image](https://user-images.githubusercontent.com/49547202/130899797-381176ee-9ac8-4804-9c85-bd1e4300b4b5.png)\n  \n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary style=\"font-Weight : bold; font-size : 30px; color : #E43914;\" \u003eHttp Server\u003c/summary\u003e\n  \n### Simple Http Server\n```csharp\nstatic void Main(string[] args)\n{\n    using (var httpServer = new SimpleTcp.Server.Http.HttpServer())\n    {\n        httpServer.HttpRequest += (sender, e) =\u003e\n        {\n            Console.WriteLine($\"[{e.Request.IPEndPoint}] -\u003e [{e.Request.Url}]\");\n            switch(e.Request.Url)\n            {\n                case \"/\":\n                    return new HttpResponse(HttpStatusCode.OK)\n                    {\n                        Content = Encoding.UTF8.GetBytes(\n                            \"\u003c!DOCTYPE html\u003e\" +\n                            \"\u003chtml\u003e\" +\n                            \"\u003chead\u003e\" +\n                            \"\u003cmeta charset=\\\"UTF-8\\\"\u003e\" +\n                            \"\u003ctitle\u003eSimpleTcp HttpServer Example\u003c/title\u003e\" +\n                            \"\u003c/head\u003e\" +\n                            \"\u003cbody\u003e\" +\n                            \"Hello, World !!\u003cbr/\u003e\u003ca href=\\\"https://github.com/akon47/SimpleTcp\\\"\u003eGithub\u003c/a\u003e\" +\n                            \"\u003c/body\u003e\" +\n                            \"\u003c/html\u003e\")\n                    };\n                default:\n                    return new HttpResponse(HttpStatusCode.NotFound);\n            }\n        };\n        httpServer.Start();\n\n        Console.ReadLine();\n    }\n}\n```\n\n![image](https://user-images.githubusercontent.com/49547202/131252066-8d2bb113-48f7-4dfc-8ac2-039fe28c0de3.png)\n  \n\u003c/details\u003e\n\n\n\n## 🐞 Bug Report\nIf you find a bug, please report to us posting [issues](https://github.com/akon47/SimpleTcp/issues) on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakon47%2Fsimpletcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakon47%2Fsimpletcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakon47%2Fsimpletcp/lists"}