diff --git a/dialer.go b/dialer.go index 225a79b..ebb5c12 100644 --- a/dialer.go +++ b/dialer.go @@ -54,7 +54,16 @@ func (d *netDialer) Dial() (*wire.Conn, error) { address := fmt.Sprintf("%s:%d", host, port) netConn, err := net.Dial("tcp", address) if err != nil { - return nil, util.WrapErrorf(err, util.ServerNotAvailable, "error dialing %s", address) + // Attempt to start the server and try again. + if err = StartServer(); err != nil { + return nil, util.WrapErrorf(err, util.ServerNotAvailable, "error starting server") + } + + address = fmt.Sprintf("%s:%d", host, port) + netConn, err = net.Dial("tcp", address) + if err != nil { + return nil, util.WrapErrorf(err, util.ServerNotAvailable, "error dialing %s", address) + } } conn := &wire.Conn{ diff --git a/host_client.go b/host_client.go index c74126e..ebca1b7 100644 --- a/host_client.go +++ b/host_client.go @@ -11,8 +11,8 @@ import ( HostClient communicates with host services on the adb server. Eg. + StartServer() client := NewHostClient() - client.StartServer() client.ListDevices() See list of services at https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT.