{"id":18332000,"url":"https://github.com/mrousavy/genericprotocol","last_synced_at":"2025-04-06T03:33:30.588Z","repository":{"id":44463308,"uuid":"103274477","full_name":"mrousavy/GenericProtocol","owner":"mrousavy","description":"⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐","archived":false,"fork":false,"pushed_at":"2020-06-18T08:38:20.000Z","size":106,"stargazers_count":44,"open_issues_count":5,"forks_count":17,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-21T16:21:22.392Z","etag":null,"topics":["binary","client","protocol","serialization","server","socket","sockets","tcp","transfer"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/GenericProtocol","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/mrousavy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"mrousavy","ko_fi":"mrousavy","custom":["https://paypal.me/mrousavy"]}},"created_at":"2017-09-12T13:30:25.000Z","updated_at":"2024-12-17T06:26:25.000Z","dependencies_parsed_at":"2022-08-30T02:30:50.101Z","dependency_job_id":null,"html_url":"https://github.com/mrousavy/GenericProtocol","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FGenericProtocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FGenericProtocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FGenericProtocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrousavy%2FGenericProtocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrousavy","download_url":"https://codeload.github.com/mrousavy/GenericProtocol/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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":["binary","client","protocol","serialization","server","socket","sockets","tcp","transfer"],"created_at":"2024-11-05T19:36:49.440Z","updated_at":"2025-04-06T03:33:30.117Z","avatar_url":"https://github.com/mrousavy.png","language":"C#","funding_links":["https://github.com/sponsors/mrousavy","https://ko-fi.com/mrousavy","https://paypal.me/mrousavy","https://ko-fi.com/F1F8CLXG'"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003e\n    \u003ccode class=\"rich-diff-level-one\"\u003e\u0026lt;T\u0026gt;\u003c/code\u003e\n    \u003cbr/\u003e\n    Generic Protocol\n  \u003c/h1\u003e\n\n  \u003cblockquote align=\"center\"\u003e⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐\u003c/blockquote\u003e\n\n  \u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/standard/net-standard\"\u003e\n\t\t\u003cimg src=\"https://img.shields.io/badge/.NET-Standard-lightgrey.svg\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://www.codacy.com/app/mrousavy/GenericProtocol?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=mrousavy/GenericProtocol\u0026amp;utm_campaign=Badge_Grade\"\u003e\n\t\t\u003cimg src=\"https://api.codacy.com/project/badge/Grade/6850ab93bbb445eaa7902450addfab6b\"\u003e\n\t\u003c/a\u003e\n    \u003ca href=\"https://ci.appveyor.com/project/mrousavy/genericprotocol\"\u003e\n      \u003cimg src=\"https://ci.appveyor.com/api/projects/status/vlgt97f4bpgci6pj?svg=true\"\u003e\n    \u003c/a\u003e\n\t\u003ca href=\"https://www.nuget.org/packages/GenericProtocol\"/\u003e\n\t\t\u003cimg src=\"https://img.shields.io/nuget/v/GenericProtocol.svg\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://www.nuget.org/packages/GenericProtocol/\"\u003e\n\t\t\u003cimg src=\"https://img.shields.io/nuget/dt/GenericProtocol.svg\"\u003e\n\t\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp align=\"center\"\u003e\t\n    \u003ca href='https://ko-fi.com/F1F8CLXG' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://az743702.vo.msecnd.net/cdn/kofi2.png?v=0' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\u003cp/\u003e\n\n## Why?\n\u003e Send whole objects over the net easier and faster\n\n1. Send nearly **any** .NET `object`\n(See: [supported](https://github.com/neuecc/ZeroFormatter#built-in-support-types), [custom](https://github.com/neuecc/ZeroFormatter#quick-start)) :package:\n2. Send/Receive **faster** by **buffered send/receive** and **ZeroFormatter**'s **fast (de-)serializing** :dash:\n3. Automatically **correct errors** with **TCP** and **Auto-reconnect** :white_check_mark:\n4. **Async** and **Event** based :zap:\n5. **Efficient Network Discovery** for other **GenericProtocol Hosts** :mag:\n6. **Fast binary links** for file/images/.. transfer :floppy_disk:\n7. Made with love :heart:\n\nSending objects:\n```csharp\nawait client.Send(someObject);\n```\n\n...on the other end:\n```csharp\nprivate void MyMessageReceivedCallback(SomeObject someObject) {\n  Console.WriteLine(\"I've received an object!\");\n}\n```\n\n## How?\nAdd **GenericProtocol** to your existing **.NET**/**.NET Core 2.0+**/**.NET Standard 2.0+** Project via **NuGet**:\n```\nPM\u003e Install-Package GenericProtocol\n```\n\nUse the default namespace:\n```csharp\nusing GenericProtocol;\n```\n\nAre you [connecting to a server](#client), or **are you** [the server](#server)?\n\n\n## Client\n### Connect to a [server](#server):\n```csharp\nIClient client = await Factory.StartNewClient\u003cMessageObject\u003e(\"82.205.121.132\", 1024, true);\n```\nThe Factory will **construct and connect** a new `IClient\u003cT\u003e` object, where `\u003cT\u003e` is the object\nyou want to **send over the net** (Here: `MessageObject`). This can be ([supported](https://github.com/neuecc/ZeroFormatter#built-in-support-types))\n**built in types** (`string`, `IEnumerable`, ..) or **custom types** marked with `[ZeroFormattable]` (see [here](https://github.com/neuecc/ZeroFormatter#quick-start))\n\n### Send/Receive custom objects:\n```csharp\n// MessageObject.cs\n[ZeroFormattable]\npublic struct MessageObject {\n  [Index(0)]\n  public string Sender { get; set; }\n  [Index(1)]\n  public string Recipient { get; set; }\n  [Index(2)]\n  public string Message { get; set; }\n  [Index(3)]\n  public DateTime Timestamp { get; set; }\n}\n\n// Main.cs\nIClient client = await Factory.StartNewClient\u003cMessageObject\u003e(\"82.205.121.132\", 1024);\n// MyMessageReceivedCallback will be called whenever this client receives a message\nclient.ReceivedMessage += MyMessageReceivedCallback; // void MyCallback(IPEndPoint, MessageObject)\n\nvar msgObject = new MessageObject() {\n  Sender = \"mrousavy\",\n  Recipient = \"cbarosch\",\n  Message = \"Hi server!\",\n  Timestamp = DateTime.Now\n}\nawait client.Send(msgObject);\n// (Optionally configure your Server so that it should redirect to the Recipient)\nclient.Dispose();\n```\n\n### Send large binary content\n```csharp\nIClient client = await Factory.StartNewBinaryDownlink(\"82.205.121.132\", 1024, true);\nclient.Send(bytes); // bytes can be a large file for example\nclient.Dispose();\n```\nUse `BinaryDownlinks`/`BinaryUplinks` when you just want to **send binary content** (Files, Images, ..). The binary links will skip the serialization and **send buffered right away**.\n\n### Other\n```csharp\n// Automatically try to reconnect on disconnects\nclient.AutoReconnect = true;\n// Set the reading buffer size for incoming data\nclient.ReceiveBufferSize = 2048;\n// Set the writing buffer size for outgoing data\nclient.SendBufferSize = 2048;\n// Get the current Connection status\nvar status = client.ConnectionStatus;\n// Connection to server lost handler\nclient.ConnectionLost += ...;\n```\n\n## Server\n### Start a new server:\n```csharp\nIServer server = await Factory.StartNewServer\u003cMessageObject\u003e(IPAddress.Any, 1024, true);\n```\n\n### Send/Receive your objects (`MessageObject` in this example):\n```csharp\n// Attach to the Message Received event\nserver.ReceivedMessage += MyMessageReceivedCallback; // void MyCallback(IPEndPoint, MessageObject)\n\nvar msgObject = new MessageObject() {\n  Sender = \"server\",\n  Recipient = \"mrousavy\",\n  Message = \"Hello client!\",\n  Timestamp = DateTime.Now\n}\nvar clientEndPoint = server.Clients.First(); // Get first client in connected-clients enumerable\nawait server.Send(msgObject, clientEndPoint); // Send object to given client\n```\n\n### Other\n```csharp\n// Event once a client connects\nserver.ClientConnected += ...; // void ClientConnectedCallback(IPEndPoint)\n// Event once a client disconnects\nserver.ClientDisconnected += ...; // void ClientDisconnectedCallback(IPEndPoint)\n// Set the reading buffer size for incoming data\nserver.ReceiveBufferSize = 2048;\n// Set the writing buffer size for outgoing data\nserver.SendBufferSize = 2048;\n// Set the count of maximum clients to queue on simultanious connection attempts\nserver.MaxConnectionsBacklog = 8;\n```\n\n\u003e License: [MIT](https://github.com/mrousavy/GenericProtocol/blob/master/LICENSE) | [Contributing](https://github.com/mrousavy/GenericProtocol/blob/master/CONTRIBUTING.md) | Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Fgenericprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrousavy%2Fgenericprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrousavy%2Fgenericprotocol/lists"}