1
This commit is contained in:
@@ -7,7 +7,7 @@ namespace BITKit.Net
|
||||
public static readonly KcpConfig Config = new KcpConfig(
|
||||
NoDelay: true,
|
||||
DualMode: false,
|
||||
Interval: 32, // 1ms so at interval code at least runs.
|
||||
Interval: 8, // 1ms so at interval code at least runs.
|
||||
Timeout: 8000,
|
||||
CongestionWindow: false
|
||||
|
||||
|
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using BITKit.Net.Examples;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
@@ -456,12 +457,17 @@ namespace BITKit.Net
|
||||
|
||||
public void AddRpcHandle(object rpcHandle)
|
||||
{
|
||||
var reportBuilder = new StringBuilder();
|
||||
|
||||
reportBuilder.AppendLine($"正在通过反射注册{rpcHandle.GetType().Name}");
|
||||
foreach (var methodInfo in rpcHandle.GetType().GetMethods())
|
||||
{
|
||||
var att = methodInfo.GetCustomAttribute<NetRpcAttribute>();
|
||||
if(att is null)continue;
|
||||
_rpcMethods.AddOrUpdate(methodInfo.Name, methodInfo, (s, info) => methodInfo);
|
||||
_rpcHandles.AddOrUpdate(methodInfo.Name, rpcHandle, (s, o) => rpcHandle);
|
||||
|
||||
reportBuilder.AppendLine($"Add [{methodInfo.Name}] as MethodInfo");
|
||||
}
|
||||
|
||||
foreach (var eventInfo in rpcHandle.GetType().GetEvents())
|
||||
@@ -470,7 +476,12 @@ namespace BITKit.Net
|
||||
if(att is null)continue;
|
||||
var handle = eventInfo.EventHandlerType.GetMethod("Invoke");
|
||||
_rpcMethods.AddOrUpdate(handle.Name, handle, (s, info) => handle);
|
||||
_rpcHandles.AddOrUpdate(handle.Name, rpcHandle, (s, info) => rpcHandle);
|
||||
|
||||
reportBuilder.AppendLine($"Add [{eventInfo.Name} as EventInfo]");
|
||||
}
|
||||
|
||||
BIT4Log.Log<KcpNetClient>(reportBuilder);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Action<T> handle)
|
||||
|
@@ -40,6 +40,7 @@ namespace BITKit.Net
|
||||
private readonly ConcurrentDictionary<int,DateTime> _lastHeartbeat = new();
|
||||
|
||||
private readonly ConcurrentQueue<(int id,byte[] bytes)> _sendQueue = new();
|
||||
private readonly ConcurrentDictionary<int,int> _dropCount = new();
|
||||
|
||||
private DateTime _now=DateTime.Now;
|
||||
private TimeSpan _interval=TimeSpan.FromSeconds(0.32);
|
||||
@@ -91,6 +92,7 @@ namespace BITKit.Net
|
||||
|
||||
//BIT4Log.Log<KCPNetServer>($"{Name}目前有{server.connections.Count}个链接");
|
||||
|
||||
_dropCount.Clear();
|
||||
while (_sendQueue.TryDequeue(out var value))
|
||||
{
|
||||
|
||||
@@ -100,9 +102,15 @@ namespace BITKit.Net
|
||||
}
|
||||
else
|
||||
{
|
||||
BIT4Log.Log<KCPNetServer>($"链接{value.id}已丢失,丢弃了{value.bytes.Length}个字节");
|
||||
int UpdateValueFactory(int i, int i1) => i1 + value.bytes.Length;
|
||||
|
||||
_dropCount.AddOrUpdate(value.id,value.bytes.Length,UpdateValueFactory);
|
||||
}
|
||||
}
|
||||
foreach (var (id,length) in _dropCount)
|
||||
{
|
||||
BIT4Log.Log<KCPNetServer>($"未找到链接:{id},已丢弃字节数量:{length}");
|
||||
}
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
@@ -114,6 +122,8 @@ namespace BITKit.Net
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void StartServer(ushort port = 27014)
|
||||
{
|
||||
if (IsRunningServer is false)
|
||||
|
Reference in New Issue
Block a user