{"id":20885805,"url":"https://github.com/fallendev/kcp","last_synced_at":"2025-10-14T18:05:39.150Z","repository":{"id":125218997,"uuid":"578872258","full_name":"FallenDev/KCP","owner":"FallenDev","description":"KCP C# version. Thread safe, no alloc at runtime, no pressure on GC.","archived":false,"fork":false,"pushed_at":"2022-12-23T03:26:39.000Z","size":2232,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T22:36:03.383Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":false,"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/FallenDev.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"publiccode":null,"codemeta":null},"funding":{"github":null,"custom":["https://github.com/KumoKyaku/KumoKyaku.github.io/blob/develop/source/_posts/%E5%9B%BE%E5%BA%8A/alipay.png","https://paypal.me/kumokyaku?country.x=C2\u0026locale.x=zh_XC"]}},"created_at":"2022-12-16T04:38:46.000Z","updated_at":"2023-08-22T06:29:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"41a323d1-0672-4131-a360-fd86f8a649be","html_url":"https://github.com/FallenDev/KCP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FallenDev/KCP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FallenDev%2FKCP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FallenDev%2FKCP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FallenDev%2FKCP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FallenDev%2FKCP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FallenDev","download_url":"https://codeload.github.com/FallenDev/KCP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FallenDev%2FKCP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020322,"owners_count":26086864,"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-10-14T02:00:06.444Z","response_time":60,"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":[],"created_at":"2024-11-18T08:14:42.545Z","updated_at":"2025-10-14T18:05:39.121Z","avatar_url":"https://github.com/FallenDev.png","language":"C#","funding_links":["https://github.com/KumoKyaku/KumoKyaku.github.io/blob/develop/source/_posts/%E5%9B%BE%E5%BA%8A/alipay.png","https://paypal.me/kumokyaku?country.x=C2\u0026locale.x=zh_XC"],"categories":[],"sub_categories":[],"readme":"# KCP C# .NET 7 \nWorks out of the box for client \u0026 server communication. This implementation is using .NET 7, support for older frameworks was removed.\n[![CodeFactor](https://www.codefactor.io/repository/github/fallendev/kcp/badge)](https://www.codefactor.io/repository/github/fallendev/kcp)\n## Features:\n\n- Asynchronous API standard interface IKcpIO.cs\n  - ValueTask Recv(IBufferWriter\u003cbyte\u003e writer, object option = null);\n  - ValueTask Output(IBufferWriter\u003cbyte\u003e writer, object option = null);\n  - Comes with a basic implementation.  KcpIO.cs\n- The generalization of kcpSegment can be implemented by user-defined high-performance.\n  - `KcpCore\u003cSegment\u003e`  where Segment : IKcpSegment\n  - `KcpIO\u003cSegment\u003e` : `KcpCore\u003cSegment\u003e`, IKcpIO  where Segment : IKcpSegment\n  - `Kcp\u003cSegment\u003e` : `KcpCore\u003cSegment\u003e` where Segment:IKcpSegment\n\n## Links:\n\nc: skywind3000 [KCP](https://github.com/skywind3000/kcp)  \ngo: xtaci [kcp-go](https://github.com/xtaci/kcp-go)  \n\n## Architecture:\n\n- Unsafe code and unmanaged memory are used internally, which will not cause pressure on gc.\n- Support user-defined memory management methods, if you don't want to use unsafe mode, you can use memory pool.\n- For output callback and TryRecv function. Use the RentBuffer callback to allocate memory externally. Please refer to [IMemoryOwner](https://docs.microsoft.com/en-us/dotnet/standard/memory-and-spans/memory-t-usage-guidelines) usage.\n- Support `Span\u003cbyte\u003e`\n\n## Thread Safety:\nSimply put: \nWhen thread 1 calls Recv/Update, thread 2 is also calling Recv/Update. A large number of shared data structures are used inside the function, and if locked, performance will be seriously affected.    \nWhen thread 1 calls Send/Input, thread 2 is also calling Send/Input. There are locks inside the function.\n\n- Send and Input can be called simultaneously from any number of threads. \n  It is safe for multiple threads to send messages at the same time, and you can safely send messages in asynchronous functions.  \n- But `cannot` multiple threads call Recv and Update at the same time.\n  The method with the same name can only be called by one thread at the same time, otherwise it will cause a multi-thread error. \n\n## Test:\nTraverse to your compiled Test Client project \u0026 Test Server project. Run both, and follow the prompts on Test Client Console.\n\n![image](https://user-images.githubusercontent.com/12104989/208140809-ed5cedc2-f878-4e98-9311-66aee2d5b413.png)\n\n[[Fixed]~~ Two Kcp echo tests in the same process, use at least 3 threads, otherwise it may deadlock.  ~~](Image/deadlock.jpg)\n\nExecute dotnet test under the path of UnitTestProject1 to perform multi-framework testing.  (need to install dotnetcoreSDK)\n\n## Some changes from the C version：\n\n| Differential change        | Version C           | C# version                                                 |\n| ---------------- | -------------- | ----------------------------------------------------- |\n| data structure       |                |                                                       |\n| acklist          | array          | ConcurrentQueue                                       |\n| snd_queue        | Doubly linked list       | ConcurrentQueue                                       |\n| snd_buf          | Doubly linked list      | LinkedList                                            |\n| rcv_buf          | Doubly linked list       | LinkedList                                            |\n| rcv_queue        | Doubly linked list      | List                                                  |\n| --------------   | -------------- | --------------                                        |\n| Callback        |                | Added the RentBuffer callback, which can apply for memory from the outside when KCP needs it. |\n| Multithreading          |                | Increased thread safety.                                      |\n| Streaming Mode          |                | Stream mode has been removed due to data structure changes.                    |\n| interval minimum interval | 10ms           | 0ms (CPU is allowed to run at full load under special circumstances)                   |\n| --------------   | -------------- | --------------                                        |\n| API change         |                |                                                       |\n|                  |                | Increase endian encoding settings. Default little-endian encoding.                    |\n|                  |                | Add the TryRecv function, and only peeksize once when Recv is possible.         |\n|                  | ikcp_ack_push  | This function was removed (inlined)                                |\n|                  | ikcp_ack_get   | This function was removed (inlined)                                |\n\n\n---\n---\n## Sponsored Link\n\n![Alipay](https://github.com/KumoKyaku/KumoKyaku.github.io/blob/develop/source/_posts/%E5%9B%BE%E5%BA%8A/alipay.png)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallendev%2Fkcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffallendev%2Fkcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallendev%2Fkcp/lists"}