Example #1
0
        // 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);
            }
        }
Example #2
0
        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;
            }
        }
Example #3
0
 public Message(Type type, string body)
 {
     this.type = EnumProtocal.Encode(type);
     this.time = Time.time;
     this.body = body;
 }