Skip to content

Commit

Permalink
优化 KCP 丢包问题
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Nov 17, 2023
1 parent f098c13 commit 9e906fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
13 changes: 5 additions & 8 deletions Hive.Network.Kcp/KcpSession.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Buffers;
using System.IO;
using System.IO.Pipelines;
using System.Net;
using System.Net.Sockets.Kcp;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -29,7 +26,7 @@ public KcpSession(

Conv = conv;

Kcp = CreateNewKcpManager(conv);
Kcp = CreateNewKcpManager(Conv);

LocalEndPoint = localEndPoint;
RemoteEndPoint = remoteEndPoint;
Expand Down Expand Up @@ -88,10 +85,10 @@ public override ValueTask<int> ReceiveOnce(ArraySegment<byte> buffer, Cancellati
private static UnSafeSegManager.KcpIO CreateNewKcpManager(uint conv)
{
var kcp = new UnSafeSegManager.KcpIO(conv);
kcp.NoDelay(2, 5, 2, 1);
kcp.WndSize(1024, 1024);
//kcp.SetMtu(512);
kcp.fastlimit = -1;
kcp.NoDelay(1, 10, 2, 1);
// kcp.WndSize(128, 128);
// kcp.SetMtu(512);
// kcp.fastlimit = -1;

return kcp;
}
Expand Down
5 changes: 3 additions & 2 deletions Hive.Network.Tests/BasicNetworking/SessionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public async Task TestSessionCreate()
tcs.SetCanceled(_cts.Token);
});

_acceptor.OnSessionCreated += (_, id, session) =>
_acceptor.OnSessionCreated += (_, _, session) =>
{
sessionCount++;
_serverSideSessions.Add(session);
Expand Down Expand Up @@ -254,10 +254,11 @@ public async Task TestSessionSendAndReceive()

if (SendInterval > 0)
await Task.Delay(SendInterval); // 防止UDP丢包

await session.TrySendAsync(ms);
}

await Task.Delay(3000);
await Task.Delay(6000);

Assert.Multiple(() =>
{
Expand Down

0 comments on commit 9e906fa

Please sign in to comment.