//Disconnecting from server /* public void Disconnect() * { * if (netstream != null) * { * netstream.Close(); * netstream.Dispose(); * } * if (tcpclient != null) * { * tcpclient.Close(); * tcpclient.Dispose(); * } * }*/ //Mathod for getting data from client private void paradicat(object obj) { TcpClient tcpclient = null; NetworkStream netstream = null; var listener = new TcpListener(IPAddress.Any, port); listener.Start(); tcpclient = listener.AcceptTcpClient(); netstream = tcpclient.GetStream(); Console.WriteLine("The simulator is connected!"); while (true) { try { if (TcpHelper.GetState(tcpclient) == System.Net.NetworkInformation.TcpState.Closed) { Console.WriteLine("Client disconnected gracefully"); break; } Data = Read(netstream); } catch (ObjectDisposedException) { Console.WriteLine("netstream has died"); } } tcpclient.Close(); netstream.Close(); listener.Stop(); tcpclient.Dispose(); netstream.Dispose(); }