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 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); }