public static void MsgPing(ClientSocket c, MsgBase msgBase) { c.LastPingTime = ServerSocket.GetTimeStamp(); MsgPing msPong = new MsgPing(); ServerSocket.SendMessage(c, msPong); }
public static void Main(string[] args) { ReceiveQueue.Start(PacketHandler.Handle); ServerSocket.Start(13338); Console.WriteLine($"Server running!"); var t = new Thread(() => { Console.WriteLine($"Heartbeat Thread started."); while (true) { foreach (var kvp in Collections.Players) { var player = kvp.Value; if (DateTime.Now >= player.LastPing.AddSeconds(1)) { Console.WriteLine($"Sending Ping to {player.Name}/{player.Username}."); player.Socket.Send(MsgPing.Create(player.UniqueId)); player.LastPing = DateTime.Now; } } Thread.Sleep(1); } }); t.Start(); while (true) { Console.ReadLine(); } }
public static void PingUpdate() { if (!isUserPing) { return; } //send if (Time.time - lastPingTime > PingInterval) { MsgPing msgPing = new MsgPing(); Send(msgPing); lastPingTime = Time.time; } //pong if (Time.time - lastPongTime > PingInterval * 4) { Close(); } }
private static void PingUpdate() { if (!isUserPing) { return; } //send if (GetTimeStamp() - lastPingTime > PingInterval) { MsgPing msgPing = new MsgPing(); Send(msgPing); lastPingTime = GetTimeStamp(); } //pong if (GetTimeStamp() - lastPongTime > PingInterval * 4) { Close(); } }
void PingThread() { while (m_Socket != null && m_Socket.Connected) { long timeNow = GetTimeStamp(); if (timeNow - lastPingTime > m_PingInterval) { MsgPing msgPing = new MsgPing(); SendMessage(msgPing); lastPingTime = GetTimeStamp(); } //如果心跳包过长时间没收到,就关闭连接 if (timeNow - lastPongTime > m_PingInterval * 4) { ClientClose(); } } }
//发送PING协议 private static void PingUpdate() { //是否启用 if (!isUsePing) { return; } //发送PING if (Time.time - lastPingTime > pingInterval) { MsgPing msgPing = new MsgPing(); Send(msgPing); lastPingTime = Time.time; } //检测PONG时间 if (Time.time - lastPongTime > pingInterval * 4) { Close(); } }