心跳包处理

This commit is contained in:
DESKTOP-SAJ6RKV\Administrator 2025-06-11 14:22:24 +08:00
parent 16ec2247d8
commit 3159ada61c

View File

@ -94,7 +94,7 @@ namespace GameLogic
}
}
float timerDt = 2;
public void OnUpdate()
{
if (m_WebSocket != null && m_WebSocket.ReadyState == WebSocketState.Open)
@ -117,8 +117,26 @@ namespace GameLogic
item.Value.Clear();
}
timerDt -= Time.deltaTime;
if (timerDt <= 0)
{
// 执行一次Ack
timerDt = 2;
OnHbTimer();
}
}
/// <summary>
/// 心跳包
/// </summary>
private void OnHbTimer()
{
// 心跳包
Dictionary<string, string> dis = new Dictionary<string, string>();
dis.Add("type", "hb");
m_WebSocket.SendAsync(dis.ToJson());
}
/// <summary>
/// 测试服流程初始化