示例#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);
            }
        }
示例#2
0
文件: Message.cs 项目: W-Siqi/SiNet
 public Message(Type type, string body)
 {
     this.type = EnumProtocal.Encode(type);
     this.time = Time.time;
     this.body = body;
 }