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 void CloseNotCallback() { Connection -= new ConnectionOk(OnTcpIPClientConnected); DataOn -= new DataOn(OnTcpIPClientReceived); Disconnection -= new ExceptionDisconnection(OnTcpIPClientDisconnected); TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Intro, "[NetworkClose]:Nothing")); base.Close(); mConnected = false; }
public override void Close() { //if (null != mSendMessageThread) //{ // mSendMessageThread.Abort(); // mSendMessageThread = null; // while (TcpIPMessageQueue.DequeueSend() != null) ; //} TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Intro, "[NetworkClose]:Nothing")); base.Close(); mConnected = false; Connection -= new ConnectionOk(OnTcpIPClientConnected); DataOn -= new DataOn(OnTcpIPClientReceived); Disconnection -= new ExceptionDisconnection(OnTcpIPClientDisconnected); }
void OnTcpIPClientConnected(string message, bool IsConn) { mConnected = IsConn; if (IsConn) { TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Intro, "[OnTcpIPClientConnected1]" + message)); //mSendMessageThread = new Thread(new ParameterizedThreadStart(SendMessageThreading)); //mSendMessageThread.Start(this); } else { TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Intro, "[ff0000][OnTcpIPClientConnected2]" + message)); TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Error, message)); } }
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()); }
void OnTcpIPClientDisconnected(string message) { //if (null != mSendMessageThread) //{ // mSendMessageThread.Abort(); // mSendMessageThread = null; // while (TcpIPMessageQueue.DequeueSend() != null) ; //} mConnected = false; //if (LocalPlayer.Inst.InLoginState) // TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CPromptMode.Intro信息, "[OnTcpIPClientDisconnected]" + message)); //else TcpIPMessageQueue.EnqueueRecv(S2C_Hint.Builder(S2CHintType.Error, message)); if (null != OnDisConnected) { OnDisConnected(message); } }
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); }