Skip to content

Commit

Permalink
[修复]1. 修复网络消息监听错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
AlianBlank committed Dec 17, 2024
1 parent 9cb3739 commit f52c171
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Runtime/Network/Helper/DefaultNetworkChannelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Initialize(INetworkChannel netChannel)
Event.Subscribe(NetworkClosedEventArgs.EventId, OnNetClosed);
Event.Subscribe(NetworkMissHeartBeatEventArgs.EventId, OnNetMissHeartBeat);
Event.Subscribe(NetworkErrorEventArgs.EventId, OnNetError);
Event.Subscribe(NetworkConnectedEventArgs.EventId, OnNetCustomError);
Event.Subscribe(NetworkCustomErrorEventArgs.EventId, OnNetCustomError);
}

public void Shutdown()
Expand All @@ -113,7 +113,7 @@ public void Shutdown()
Event.Unsubscribe(NetworkClosedEventArgs.EventId, OnNetClosed);
Event.Unsubscribe(NetworkMissHeartBeatEventArgs.EventId, OnNetMissHeartBeat);
Event.Unsubscribe(NetworkErrorEventArgs.EventId, OnNetError);
Event.Unsubscribe(NetworkConnectedEventArgs.EventId, OnNetCustomError);
Event.Unsubscribe(NetworkCustomErrorEventArgs.EventId, OnNetCustomError);
m_NetworkChannel = null;
}

Expand Down Expand Up @@ -178,7 +178,7 @@ private void OnNetConnected(object sender, GameEventArgs e)
return;
}

Log.Info("网络连接成功......");
Log.Info($"网络连接成功......{ne.NetworkChannel.Name}");
}

private void OnNetClosed(object sender, GameEventArgs e)
Expand All @@ -188,15 +188,13 @@ private void OnNetClosed(object sender, GameEventArgs e)
return;
}

Log.Info("网络连接关闭......");
Log.Info($"网络连接关闭......{ne.NetworkChannel.Name}");
}

private void OnNetMissHeartBeat(object sender, GameEventArgs e)
{
if (!(e is NetworkMissHeartBeatEventArgs ne) || ne.NetworkChannel != m_NetworkChannel) return;
Log.Warning(Utility.Text.Format("Network channel '{0}' miss heart beat '{1}' times.", ne.NetworkChannel.Name, ne.MissCount));
// if (ne.MissCount < 2) return;
// ne.NetChannel.Close();
}

private void OnNetError(object sender, GameEventArgs e)
Expand All @@ -216,6 +214,8 @@ private void OnNetCustomError(object sender, GameEventArgs e)
{
return;
}

Log.Error(Utility.Text.Format("Network channel '{0}' error", ne.NetworkChannel.Name));
}
}
}

0 comments on commit f52c171

Please sign in to comment.