public void Disconnect() { StreamProvider.Dispose(); TcpClient.Close(); TcpClient = null; StreamProvider = null; }
public void StartListening() { TcpClient.ReceiveTimeout = 600000; while (true) { try { if (TcpClient.Client.Poll(0, SelectMode.SelectRead)) { byte[] checkConn = new byte[1]; if (TcpClient.Client.Receive(checkConn, SocketFlags.Peek) == 0) { throw new IOException(); } } var command = StreamProvider.StreamReader.ReadLine(); Commander.ExecuteCommand(command, StreamProvider); } catch (Exception) { break; } } if (Disconnected != null) { Disconnected(this, EventArgs.Empty); } if (StreamProvider != null) { StreamProvider.Dispose(); } if (TcpClient != null) { TcpClient.Close(); } }