Resets the statistics that are returned from NetworkClient.GetConnectionStats().
internal virtual void Update() { if (m_ClientId == -1) { return; } switch (m_AsyncConnect) { case ConnectState.None: case ConnectState.Resolving: case ConnectState.Disconnected: return; case ConnectState.Failed: GenerateConnectError(11); m_AsyncConnect = ConnectState.Disconnected; return; case ConnectState.Resolved: m_AsyncConnect = ConnectState.Connecting; ContinueConnect(); return; } if (m_Connection != null && (int)Time.time != m_StatResetTime) { m_Connection.ResetStats(); m_StatResetTime = (int)Time.time; } NetworkEventType networkEventType; do { int num = 0; networkEventType = NetworkTransport.ReceiveFromHost(m_ClientId, out int _, out int channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out int receivedSize, out byte error); if (networkEventType != NetworkEventType.Nothing && LogFilter.logDev) { Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEventType + " error=" + error); } switch (networkEventType) { case NetworkEventType.ConnectEvent: if (LogFilter.logDebug) { Debug.Log("Client connected"); } if (error != 0) { GenerateConnectError(error); return; } m_AsyncConnect = ConnectState.Connected; m_Connection.InvokeHandlerNoData(32); break; case NetworkEventType.DataEvent: if (error != 0) { GenerateDataError(error); return; } m_MsgReader.SeekZero(); m_Connection.TransportRecieve(m_MsgBuffer, receivedSize, channelId); break; case NetworkEventType.DisconnectEvent: if (LogFilter.logDebug) { Debug.Log("Client disconnected"); } m_AsyncConnect = ConnectState.Disconnected; if (error != 0) { GenerateDisconnectError(error); } ClientScene.HandleClientDisconnect(m_Connection); m_Connection.InvokeHandlerNoData(33); break; default: if (LogFilter.logError) { Debug.LogError("Unknown network message type received: " + networkEventType); } break; case NetworkEventType.Nothing: break; } if (num + 1 >= 500) { if (LogFilter.logDebug) { Debug.Log("MaxEventsPerFrame hit (" + 500 + ")"); } break; } }while (m_ClientId != -1 && networkEventType != NetworkEventType.Nothing); if (m_Connection != null && m_AsyncConnect == ConnectState.Connected) { m_Connection.FlushChannels(); } }
internal virtual void Update() { if (m_ClientId == -1) { return; } switch (m_AsyncConnect) { case ConnectState.None: case ConnectState.Resolving: case ConnectState.Disconnected: return; case ConnectState.Failed: GenerateConnectError((int)NetworkError.DNSFailure); m_AsyncConnect = ConnectState.Disconnected; return; case ConnectState.Resolved: m_AsyncConnect = ConnectState.Connecting; ContinueConnect(); return; case ConnectState.Connecting: case ConnectState.Connected: { break; } } if (m_Connection != null) { if ((int)Time.time != m_StatResetTime) { m_Connection.ResetStats(); m_StatResetTime = (int)Time.time; } } NetworkEventType networkEvent; do { int connectionId; int channelId; int receivedSize; byte error; int numEvents = 0; networkEvent = NetworkTransport.ReceiveFromHost(m_ClientId, out connectionId, out channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out receivedSize, out error); if (networkEvent != NetworkEventType.Nothing) { if (LogFilter.logDev) { Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEvent + " error=" + error); } } switch (networkEvent) { case NetworkEventType.ConnectEvent: if (LogFilter.logDebug) { Debug.Log("Client connected"); } if (error != 0) { GenerateConnectError(error); return; } m_AsyncConnect = ConnectState.Connected; m_Connection.InvokeHandlerNoData(MsgType.Connect); break; case NetworkEventType.DataEvent: if (error != 0) { GenerateDataError(error); return; } #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, MsgType.LLAPIMsg, "msg", 1); #endif m_MsgReader.SeekZero(); m_Connection.TransportRecieve(m_MsgBuffer, receivedSize, channelId); break; case NetworkEventType.DisconnectEvent: if (LogFilter.logDebug) { Debug.Log("Client disconnected"); } m_AsyncConnect = ConnectState.Disconnected; if (error != 0) { if ((NetworkError)error != NetworkError.Timeout) { GenerateDisconnectError(error); } } ClientScene.HandleClientDisconnect(m_Connection); if (m_Connection != null) { m_Connection.InvokeHandlerNoData(MsgType.Disconnect); } break; case NetworkEventType.Nothing: break; default: if (LogFilter.logError) { Debug.LogError("Unknown network message type received: " + networkEvent); } break; } if (++numEvents >= k_MaxEventsPerFrame) { if (LogFilter.logDebug) { Debug.Log("MaxEventsPerFrame hit (" + k_MaxEventsPerFrame + ")"); } break; } if (m_ClientId == -1) { break; } }while (networkEvent != NetworkEventType.Nothing); if (m_Connection != null && m_AsyncConnect == ConnectState.Connected) { m_Connection.FlushChannels(); } }