[C#]TcpClient斷線例外

TcpClient如果直接斷開連線…

之後再連線就會出現通訊埠已開啟無法連線

 

解決方法就

if (!tcpClient.Connected)//沒連線
{
           tcpClient.Client.Close();
           tcpClient.Close();
           tcpClient = new TcpClient();
           System.GC.Collect();
}