 (defn setup
   [repl-env opts]
   (let [_ (set-logging-level "javax.jmdns" java.util.logging.Level/SEVERE)
-        discovered-endpoints (discover-ambly-webdav-bonjour-services 15000)
-        _ (when (empty? discovered-endpoints)
-            (throw (Exception. "No device or simulator running Ambly discovered.")))
-        ; TODO Need some UI and/config facilitating picking an Ambly instance
-        [webdav-endpoint-name webdav-endpoint] (first discovered-endpoints)
+        [webdav-endpoint-name webdav-endpoint] (discover-and-pick-ambly-instance)
+        _ (println "\nConnecting to" (service-name->display-name webdav-endpoint-name) "...\n")
         ; Assuming IPv4 for now
         endpoint-address (.getHostAddress (:address webdav-endpoint))
         endpoint-port (:port webdav-endpoint)

              (when (.startsWith name "Ambly WebDAV Server")
                (.requestServiceInfo mdns-service (.getType service-event) (.getName service-event) 1))))
          (serviceRemoved [_ service-event]
            #_(swap! discovered-services dissoc (.getName service-event)))
          (serviceResolved [_ service-event]
            (let [entry {(.getName service-event)
                         (let [info (.getInfo service-event)]
                           {:address (.getAddress info)
                            :port    (.getPort info)})}]
              #_(swap! discovered-services merge entry)
              (deliver discovered-services entry))))]
    (try
      (.addServiceListener mdns-service reg-type service-listener)
      #_(Thread/sleep timeout)
      (deref discovered-services timeout {})
      (finally
        (.removeServiceListener mdns-service reg-type service-listener)
        (.close mdns-service)))))

(defn socket [host port]
  (let [socket (Socket. host port)

        _ (.mkdirs output-dir)
        env (ana/empty-env)
        core (io/resource "cljs/core.cljs")]
    (reset! (:webdav-mount-point repl-env) webdav-mount-point)
    (shell/sh "mount_webdav" (str "http://" endpoint-address ":" endpoint-port) webdav-mount-point)
    (reset! (:socket repl-env)
