// TBD: potential bug: online and isConnected sync problem IEnumerator ConnectionCheckLoop() { while (true) { if (!serverConnection.isConnected && online) { // first lost connection online = false; OnConnectLost(); Debug.Log("to offLine mode!"); } else if (!serverConnection.isConnected && !online) { // re connect // 重构!!! Message response = new Message(Message.Type.none, ""); serverConnection.Connect(null, response); yield return(new WaitForSeconds(1f)); if (response.type != EnumProtocal.Encode(Message.Type.none)) { online = true; OnConnectSuccess(response); } else { Debug.LogError("TimeOut"); } } yield return(CONNECTION_CHECK_INTERVAL); } }
public static void Process(Message message) { switch (EnumProtocal.Decode(message.type)) { case Message.Type.syncMessage: ProcessSyncMessage(message); break; default: Debug.LogError("cannot handle this type yet"); break; } }
public Message(Type type, string body) { this.type = EnumProtocal.Encode(type); this.time = Time.time; this.body = body; }