               (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)))
+            (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))))]
+              (swap! discovered-services merge entry))))]
     (try
       (.addServiceListener mdns-service reg-type service-listener)
-      #_(Thread/sleep timeout)
-      (deref discovered-services timeout {})
+      (loop [count 0]
+        (when (empty? @discovered-services)
+          (Thread/sleep 100)
+          (when (= 1000 count)
+            (println "\nSearching ..."))
+          (recur (inc count))))
+      (Thread/sleep 500)                                    ;; Sleep a little more to catch stragglers
+      (loop [current-discovered-services @discovered-services]
+        (println)
+        (print-services current-discovered-services)
+        (println "\n[r] Refresh\n")
+        (print "Choice: ")
+        (flush)
+        (let [choice (read-line)]
+          (if (= "r" choice)
+            (recur @discovered-services)
+            (let [choices (service-map->choice-list current-discovered-services)
+                  choice-ndx (try (dec (Long/parseLong choice)) (catch NumberFormatException _ nil))]
+              (if (< -1 choice-ndx (count choices))
+                (second (nth choices choice-ndx))
+                (recur current-discovered-services))))))
       (finally
-        (.removeServiceListener mdns-service reg-type service-listener)
-        (.close mdns-service)))))
+        (future
+          (.removeServiceListener mdns-service reg-type service-listener)
+          (.close mdns-service))))))
 
 (defn socket [host port]
   (let [socket (Socket. host port)

(defn set-logging-level [logger-name level]
  (.setLevel (java.util.logging.Logger/getLogger logger-name) level))

;; For now, this impl simply returns the first service as soon as it is discovered
(defn discover-ambly-webdav-bonjour-services
  "Looks for Ambly WebDAV services advertised via Bonjour."
  [timeout]
  (let [reg-type "_http._tcp.local."
        ;discovered-services (atom {})
        discovered-services (promise)
        mdns-service (JmDNS/create)
        service-listener
        (reify ServiceListener

        _ (.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)
