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 void AsyncUnLockNetMsgScreenLocked() { lock (mWaitUnlockMsgs) { mWaitUnlockMsgs.Clear(); } TcpIPMessageQueue.EnqueueRecv(LocalAsyncToMainThread.Builder(LocalAsyncToMainThreadType.UnlockScreen)); }
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()); }
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); }