Kcp 2.6.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kcp --version 2.6.3                
NuGet\Install-Package Kcp -Version 2.6.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kcp" Version="2.6.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kcp --version 2.6.3                
#r "nuget: Kcp, 2.6.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kcp as a Cake Addin
#addin nuget:?package=Kcp&version=2.6.3

// Install Kcp as a Cake Tool
#tool nuget:?package=Kcp&version=2.6.3                

KCP C#版

开箱即用。也可以使用 Nuget 搜索。

Nuget

Feature:

  • 异步API标准接口 IKcpIO.cs
    • ValueTask Recv(IBufferWriter<byte> writer, object option = null);
    • ValueTask Output(IBufferWriter<byte> writer, object option = null);
    • 附带一个基本实现。KcpIO.cs
  • kcpSegment泛型化,可由用户自定义高性能实现。
    • KcpCore<Segment> where Segment : IKcpSegment
    • KcpIO<Segment> : KcpCore<Segment>, IKcpIO where Segment : IKcpSegment
    • Kcp<Segment> : KcpCore<Segment> where Segment:IKcpSegment

链接:

c: skywind3000 KCP
go: xtaci kcp-go

说明:

  • 内部使用了unsafe代码和非托管内存,不会对gc造成压力。
  • 支持用户自定义内存管理方式,如果不想使用unsafe模式,可以使用内存池.
  • 对于output回调和TryRecv函数。使用RentBuffer回调,从外部分配内存。请参考IMemoryOwner用法。
  • 支持Span<byte>

线程安全

简单的说:
不能在线程1调用Recv/Update时,线程2也在调用Recv/Update。函数内部使用大量共享数据结构,如果加锁严重影响性能。
可以在线程1调用Send/Input时,线程2也在调用Send/Input。函数内部有锁。

  • 可以在任意多线程同时调用Send 和 Input。
    多线程同时发送消息是安全的,可以放心的在异步函数中发送消息。
  • 不可以多个线程同时调用Recv 和 Update。
    同名方法仅支持一个线程同时调用,否则会导致多线程错误。

测试:

[已修复]同一个进程两个Kcp echo测试,至少使用3个线程,否则可能死锁。

在UnitTestProject1路径下执行 dotnet test 可进行多框架测试。(需要安装dotnetcoreSDK)

相对C版的一些变化:

差异变化 C版 C#版
数据结构
acklist 数组 ConcurrentQueue
snd_queue 双向链表 ConcurrentQueue
snd_buf 双向链表 LinkedList
rcv_buf 双向链表 LinkedList
rcv_queue 双向链表 List
-------------- -------------- --------------
回调函数 增加了RentBuffer回调,当KCP需要时可以从外部申请内存。
多线程 增加了线程安全。
流模式 由于数据结构变动,移除了流模式。
interval最小间隔 10ms 0ms(在特殊形况下允许CPU满负荷运转)
-------------- -------------- --------------
API变动
增加大小端编码设置。默认小端编码。
增加TryRecv函数,当可以Recv时只peeksize一次。
ikcp_ack_push 删除了此函数(已内联)
ikcp_ack_get 删除了此函数(已内联)


赞助链接

支付宝

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Kcp:

Package Downloads
EasySharpFrame

Simple Development!

Megumin.Remote

NetRemoteStandard的一个实现。

KCPNet

基于UDP以及开源项目Protobuf实现的帧同步网络库

YaoYuan.CoreServerSocket

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Kcp:

Repository Stars
KumoKyaku/Megumin.Net
应用程序和游戏网络模块解决方案
suxf/ECSharp
Easy .NET Develop Frame.
Version Downloads Last updated
2.7.0 1,684 11/16/2023
2.6.3 478 7/12/2023
2.6.2 224 6/16/2023
2.6.1 1,675 1/12/2023
2.6.0 1,233 10/29/2022
2.5.2 878 10/14/2022
2.5.1 364 10/10/2022
2.5.0 400 10/10/2022
2.4.1 387 10/7/2022
2.4.0 1,532 8/17/2022
2.3.0 8,723 9/16/2021
2.2.2 579 3/9/2021
2.2.1 388 2/4/2021
2.2.0 425 1/13/2021
2.1.0 668 12/2/2020
2.0.0 12,133 12/9/2019
1.3.2 735 4/5/2019
1.3.1 658 3/2/2019
1.3.0 615 3/1/2019
1.2.0 790 2/23/2019
1.1.0 602 2/21/2019
1.0.1 665 2/14/2019
1.0.0 657 2/13/2019