This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -48,14 +48,17 @@ namespace BITKit.Net
});
}
private async void Tick(object sender, ElapsedEventArgs e)
private void Tick(object sender, ElapsedEventArgs e)
{
await UniTask.SwitchToThreadPool();
//await UniTask.SwitchToThreadPool();
while (commandQueue.TryDequeue(out var bytes))
{
client.Send(bytes, KcpChannel.Reliable);
}
client.Tick();
//for (var i = 0; i < 32; i++)
{
client.Tick();
}
}
public async void Disconnect()
@@ -88,6 +91,10 @@ namespace BITKit.Net
if (BITApp.SynchronizationContext is not null)
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
OnConnected?.Invoke();
if (client.connected)
{
SendServerMessage(Environment.MachineName);
}
return client.connected;
}
catch (Exception e)
@@ -136,7 +143,7 @@ namespace BITKit.Net
break;
case NetCommandType.Heartbeat:
//client.Send(new[] { (byte)NetCommandType.Heartbeat }, KcpChannel.Reliable);
client.Send(new[] { (byte)NetCommandType.Heartbeat }, KcpChannel.Reliable);
break;
default:
BIT4Log.Log<KcpClient>($"未知消息类型:{type},字节:{(byte)type}");