KCP - A Fast and Reliable ARQ Protocol
- FEC(Forward Error Correction) Based on Reed-Solomon Codes
- Packet level encryption
KCP - A Fast and Reliable ARQ Protocol (Zero GC overhead)
License: MIT License
mKCP.PeekSize 必须读到小于0才行。
要不数据有可能收到了,但是上层读不到
请问TODO的FEC和加密在实现计划中吗
为何不实现类似kcp-go服务端的c#源码?
Flush函数中有两个匿名函数,会导致GC Alloc,初步分析是对writeIndex的闭包导致的。
有没有考虑过将这里的匿名函数改成普通函数的实现。我自己这么改了,确实能减少GC
public UInt32 Flush(bool ackOnly)
{
// other code
var writeIndex = reserved;
Action<int> makeSpace = (space) =>
{
if (writeIndex + space > mtu)
{
if (ikcp_canlog(IKCP_LOG_OUTPUT))
{
ikcp_log($"[RO] {writeIndex.ToString()} bytes");
}
output(buffer, writeIndex);
writeIndex = reserved;
}
};
Action flushBuffer = () =>
{
if (writeIndex > reserved)
{
if (ikcp_canlog(IKCP_LOG_OUTPUT))
{
ikcp_log($"[RO] {writeIndex.ToString()} bytes");
}
output(buffer, writeIndex);
}
};
// other code
}
看到介绍,可以连接kcp-go,而采用最新的kcp-csharp 及 最新的kcp-go,好像无法建立连接
我这边尝试用kcp-csharp 连接 基于kcp-go的kcptun服务端,在端口正确的情况下无法建立连接。
在kcp-go的sess.go中添加log发现问题原因为:
receiver函数中下列语句判断包为无效包
“if n, from, err := l.conn.ReadFromUDP(data); err == nil && n >= l.headerSize+IKCP_OVERHEAD”
其中,n = 34 ,l.headerSize = 28 , IKCP_OVERHEAD = 24
是kcp-go这边发生变化了吗?
如何能建立连接?
你好,我们用了这个库,用了最新的commit,7ed200bb258b7b1e54046a527bf9a91921c2e248
我们会在每一帧调用Update函数,但是今天发现有崩溃的问题,堆栈如下:
NullReferenceException: Object reference not set to an instance of an object
KcpProject.KCP.Flush (System.Boolean ackOnly) (at Assets/Framework/ThirdParty/KCP/KCP.cs:917)
KcpProject.KCP.Update () (at Assets/Framework/ThirdParty/KCP/KCP.cs:1005)
KcpProject.UDPSession.Update () (at Assets/Framework/ThirdParty/KCP/UDPSession.cs:151)
Framework.KCPClient.OnUpdateTick () (at Assets/Framework/CSharp/Network/KCPClient.cs:47)
Hi there,
Thanks for providing a good implemetation of KCP for .NET!
Are you able to add a license to the project so that people can use it? By default a repository without a license is not usable without risk of legal action etc.
KCP is MIT licensed so it would be nice to follow suit, but obviously that is your choice!
Jamie
I get error form this line (line 917)
var need = IKCP_OVERHEAD + segment.data.ReadableBytes;
the error is System.NullReferenceException: 'Object reference not set to an instance of an object.'
segment.data 'was' null
it's happened after sending 100 packets and sometimes happend after 24000 packets
System.Net.Sockets.SocketException (10054): 远程主机强迫关闭了一个现有的连接。
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at KcpProject.UDPSession.Recv(Byte[] data, Int32 index, Int32 length) in C:\Users\Admin\Downloads\ConsoleApp2\UDPSession.cs:line 133
Receive Message failed.
没有动代码,跑不通,请问是什么原因呢
I tried the example on this project but it seems the kcp for golang doesn’t work. Tried sending a message from this c# script but golang server won’t recognize it.
Hey,
is there any chance that you could provide a server example / a server kcp version too?
Would happily pay you for your work.
Let me know :)
kcp.cs里用append()和slice()来操作Segment[](rcv_que, snd_que,rcv_buf, snd_buf),而每次append和slice都会重新分配内存。
是否可以考虑使用一个nrcv_que来表示实际长度,而snd_buf.Length只表示capacity,这样修改长度的时候只需要调整nrcv_que的指向位置,不必产生大量的内存分配
我在unity5中重新写了一个测试客户端
https://github.com/RainsSoft/kcp-csharp/
测试了一天,内存稳定,没有报错,不过测试代码较为简单
每几秒发一个包的时候 丢包时候 不会立即重发 会跟下一个包一起在重发 打日志看rawSend也没有发送 可以帮忙看下吗
void init_kcp(UInt32 conv)
{
mKcp = new KCP(conv, (byte[] buf, int size) =>
{
//这里偶现的会报异常,Socket has bean shut down,这里建议怎么处理呢
mUdpClient.Send(buf, size);
});
// fast mode.
mKcp.NoDelay(1, 10, 2, 1);
mKcp.WndSize(128, 128);
}
目前预想的是这样,同时建立TCP链接和KCP链接,如果通过KCP发送不成功,就切回TCP继续发送。
请问这个大概怎么做可以实现?
code position is KCP class at "NoDelay" function
/* some code ... /
else if (interval < 10)
{
interval_ = 0; //_* bug!!!! it must be 10.**
}
/* some code ... */
i try test.. this project ^^
Send function is good
but... mRecvBuffer.ReadableBytes not work.....
how can i use this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.