/// <summary> /// Disconnect from any connected VM. /// </summary> public void Disconnect() { var conn = connection; connection = null; prepared = false; pid = -1; var oldMonitor = jdwpMonitor; jdwpMonitor = null; if (oldMonitor != null) { oldMonitor.Stop(); oldMonitor.Dispose(); } if (conn != null) { try { conn.Close(); } catch { // Ignore } } // Notify ConnectedChanged.Fire(this); }
/// <summary> /// Connect to the VM in the given process id on the given device. /// </summary> public void Connect(IDevice device, int pid, MapFile mapFile) { // Disconnect any pending connections Disconnect(); // Cleanup process = null; this.mapFile = mapFile; this.pid = pid; // Setup forward var port = GetFreePort(); var adb = new Adb(); adb.ForwardJdwp(device, port, pid); // Establish connection connection = new JdwpConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port), ChunkHandler, pid, PacketHandler); connection.Disconnect += OnConnectionDisconnect; // Notify ConnectedChanged.Fire(this); }