protected virtual void Dispose(bool disposing) { if (disposed) { return; } Switch = false; Server.Close(); Server.Dispose(); if (disposing) { Server = null; ClientThread = null; CB = null; } disposed = true; }
private string ClientWork(TcpClient ThisTcpClient, string SendMessage) { try { CommunicationBase CB = new CommunicationBase(ThisTcpClient); CB.SendMsg(SendMessage); return(CB.ReceiveMsg()); } catch { Debug.WriteLine("客戶端強制關閉連線!"); ThisTcpClient.Close(); ThisTcpClient.Dispose(); lock (ClientsLock) if (Clients.Contains(ThisTcpClient)) { Clients.Remove(ThisTcpClient); } } return(string.Empty); }
public void Start(string MD5String) { if (Server.Connected) { Debug.WriteLine("連線成功!"); CB = new CommunicationBase(Server); if (CB.ReceiveMsg() == MD5String) { CB.SendMsg("success"); ClientThread = new Thread(TCPClientWork) { IsBackground = true }; ClientThread.Start(); } else { CB.SendMsg("Fail"); Server.Close(); Server.Dispose(); throw new ArgumentException("MD5檢查失敗"); } } }