示例#1
0
        public bool CloseMatch(bool hint = true)
        {
            if (null != mMatchClient)
            {
                if (!CanWorking)
                {
                    throw new Exception("CloseMatch:this tcp networking cannot working, because mNetworkingModel is null");
                }
                if (hint)
                {
                    mMatchClient.Close();
                }
                else
                {
                    mMatchClient.CloseNotCallback();
                }
                while (null != mMatchClient && mMatchClient.Connected)
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                { continue; }
#else
                { Thread.Sleep(1); }
#endif
                mMatchClient = null;
                if (hint)
                {
                    TcpIPMessageQueue.EnqueueRecv(LocalAsyncToMainThread.Builder(LocalAsyncToMainThreadType.MatchDisconnection));
                }
                AsyncUnLockNetMsgScreenLocked();
            }
            return(true);
        }
        public static IS2C_Msg Builder(LocalAsyncToMainThreadType type)
        {
            var msg = new LocalAsyncToMainThread();

            msg.type = type;
            return(msg);
        }
示例#3
0
 public void AsyncUnLockNetMsgScreenLocked()
 {
     lock (mWaitUnlockMsgs)
     {
         mWaitUnlockMsgs.Clear();
     }
     TcpIPMessageQueue.EnqueueRecv(LocalAsyncToMainThread.Builder(LocalAsyncToMainThreadType.UnlockScreen));
 }
        public static IS2C_Msg Builder(Stream buffer)
        {
            var  msg  = new LocalAsyncToMainThread();
            Byte type = 0;

            StreamUtils.Read(buffer, ref type);
            msg.type = (LocalAsyncToMainThreadType)type;
            return(msg);
        }
 public static void SendHeart()
 {
     //LocalPlayer lp = LocalPlayer.Inst;
     //if (null != lp && lp.InSceneState)
     {
         if (mHeartTick >= 4)
         {
             TcpIPMessageQueue.EnqueueRecv(LocalAsyncToMainThread.Builder(LocalAsyncToMainThreadType.Disconnection));
             mHeartTick = 0;
             return;
         }
     }
     TcpIPNetwork.Inst.SendMessage(C2S_HeartTicker.Create());
     mLastSendHeartTime = Time.realtimeSinceStartup;
     //if (null != lp && lp.InSceneState)
     mHeartTick++;
     Debug.Log("发送心跳包:" + mLastSendHeartTime.ToString() + ", cnt=" + mHeartTick.ToString());
 }
示例#6
0
 public bool ConnectMatchServer(string address, int port)
 {
     if (!CanWorking)
     {
         throw new Exception("ConnectMatchServer:this tcp networking cannot working, because mNetworkingModel is null");
     }
     if (null != mMatchClient)
     {
         Debug.LogWarning(string.Format("关闭当前连接后才能与服务器[{0}:{1}]建立连接!", address, port));
         CloseMatch(false);
     }
     mMatchClient = new TcpIPClient();
     mMatchClient.OnDisConnected += new TcpIPClient.DisConnected((string message) =>
     {
         mMatchClient.Close();
         mMatchClient = null;
         TcpIPMessageQueue.EnqueueRecv(LocalAsyncToMainThread.Builder(LocalAsyncToMainThreadType.MatchDisconnection));
     });
     mMatchClient.ConnectionTo(address, port);
     return(true);
 }