{"id":36924086,"url":"https://github.com/MarvinDrude/MNet","last_synced_at":"2026-01-19T18:00:39.398Z","repository":{"id":229264696,"uuid":"770340610","full_name":"MarvinDrude/MNet","owner":"MarvinDrude","description":"Fast TCP Server/Client in C# .NET 8 and newer using techniques similar to kestrel internal","archived":false,"fork":false,"pushed_at":"2024-03-31T11:51:43.000Z","size":144,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-31T12:39:12.352Z","etag":null,"topics":["async","fast","high-performance","socketasynceventargs","tcp","tcp-client","tcp-server"],"latest_commit_sha":null,"homepage":"https://marvindrude.com/","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/MarvinDrude.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-11T11:37:19.000Z","updated_at":"2024-03-31T10:13:55.000Z","dependencies_parsed_at":"2024-03-31T12:33:30.830Z","dependency_job_id":null,"html_url":"https://github.com/MarvinDrude/MNet","commit_stats":null,"previous_names":["marvindrude/mnet"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MarvinDrude/MNet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinDrude%2FMNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinDrude%2FMNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinDrude%2FMNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinDrude%2FMNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarvinDrude","download_url":"https://codeload.github.com/MarvinDrude/MNet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarvinDrude%2FMNet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28578952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T17:42:58.221Z","status":"ssl_error","status_checked_at":"2026-01-19T17:40:54.158Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","fast","high-performance","socketasynceventargs","tcp","tcp-client","tcp-server"],"created_at":"2026-01-12T19:00:25.486Z","updated_at":"2026-01-19T18:00:39.392Z","avatar_url":"https://github.com/MarvinDrude.png","language":"C#","funding_links":[],"categories":["C# #"],"sub_categories":[],"readme":"\n# MNet TCP Server/Client\n\n[NuGet](https://www.nuget.org/packages/MNet)\n\nJust a small lightweight library for TCP Communication in .NET/C#. It utilizes some techniques from internal\nkestrel sockets for some performance benefits. Some notes on things used:\n\n\n## Remarks on used technologies\n\n- Uses some \"stackalloc\" and \"MemoryPool\u003cbyte\u003e.Shared\" for less heap allocations\n- Usage of \"System.IO.Pipelines\" for better buffering\n- Custom schedulers for Tasks\n- Custom \"PinnedBlockMemoryPool\" from kestrel\n- Expression Compilation for better performance of events\n- For Secure Ssl falls back to SslStream under the hood, but still amazingly fast\n\n## Simple Usage\nYou should always first register all the event handlers before calling Server.Start/Client.Connect, in order for you to not miss any instant messages.\n\n### Creation of a TCP Server\n```csharp\nvar server = new TcpServer(new TcpServerOptions() {\n    Address = \"127.0.0.1\", \n    Port = 43434,\n    Logger = debugLogger, // ILogger of your liking, default is just console one\n    Serializer = new TcpJsonSerializer(), // by default TcpJsonSerializer, you can implement your own serializers with ITcpSerializer\n    Handshaker = new TcpServerHandshaker(), // by default no handshaking, if you need handshaking implement a ITcpServerHandshaker\n});\nserver.Start();\n```\n\n#### Connect / Disconnect (Connect event is after successful handshake)\n```csharp\nserver.OnConnect += (connection) =\u003e {\n    ...\n};\n\nserver.OnDisconnect += (connection) =\u003e {\n    ...\n};\n```\n\n#### Register event handler for raw bytes messages\n```csharp\nserver.On\u003cReadOnlyMemory\u003cbyte\u003e\u003e(\"test-bytes\", (buffer, connection) =\u003e {\n\n    // important, will only work by using ReadOnlyMemory\u003cbyte\u003e here, not byte[], Memory\u003cbyte\u003e etc.\n    Console.WriteLine(\"Length: \" + buffer.Length);\n\n    // send a raw bytes message (important for sending must be of type Memory\u003cbyte\u003e)\n    connection.Send(\"test-bytes\", new Memory\u003cbyte\u003e([0, 2, 3, 5]));\n\n});\n```\n\n#### Register event handler for serializable messages\n```csharp\nserver.On\u003cAnyClassOfYours\u003e(\"test-class\", (obj, connection) =\u003e {\n\n    if(obj == null) return;\n    Console.WriteLine(\"Length: \" + obj.ToString());\n\n    // send a serializable message\n    connection.Send(\"test-class\", new AnyClassOfYours() { A = \"Wow!\" });\n\n});\n```\n\n### Creation of a TCP Client\n```csharp\nvar client = new TcpClient(new TcpClientOptions() {\n    Address = \"127.0.0.1\",\n    Port = 43434,\n    Logger = debugLogger, // ILogger of your liking, default is just console one\n    Serializer = new TcpJsonSerializer(), // by default TcpJsonSerializer, you can implement your own serializers with ITcpSerializer\n    Handshaker = new TcpClientHandshaker(), // by default no handshaking, if you need handshaking implement a ITcpClientHandshaker\n});\nclient.Connect();\n```\n\n#### Connect / Disconnect (Connect event is after successful handshake)\n```csharp\nclient.OnConnect += () =\u003e {\n    ...\n};\n\nclient.OnDisconnect += () =\u003e {\n    ...\n};\n```\n\n#### Register event handler for raw bytes messages\n```csharp\nclient.On\u003cReadOnlyMemory\u003cbyte\u003e\u003e(\"test-bytes\", (buffer) =\u003e {\n\n    // important, will only work by using ReadOnlyMemory\u003cbyte\u003e here, not byte[], Memory\u003cbyte\u003e etc.\n    Console.WriteLine(\"Length: \" + buffer.Length);\n\n    // send a raw bytes message (important for sending must be of type Memory\u003cbyte\u003e)\n    client.Send(\"test-bytes\", new Memory\u003cbyte\u003e([0, 2, 3, 5]));\n\n});\n```\n\n#### Register event handler for serializable messages\n```csharp\nclient.On\u003cAnyClassOfYours\u003e(\"test-class\", (obj) =\u003e {\n\n    if(obj == null) return;\n    Console.WriteLine(\"Length: \" + obj.ToString());\n\n    // send a serializable message\n    client.Send(\"test-class\", new AnyClassOfYours() { A = \"Wow!\" });\n\n});\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarvinDrude%2FMNet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMarvinDrude%2FMNet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarvinDrude%2FMNet/lists"}