           (.removeServiceListener mdns-service reg-type service-listener)
           (.close mdns-service))))))
 
+(defn resolve-bonjour [bonjour-name timeout]
+  (let [reg-type "_http._tcp.local."
+        mdns-service (JmDNS/create)]
+    (try
+      (let [info (.getServiceInfo mdns-service reg-type bonjour-name timeout)]
+        (when info
+          {:address (.getAddress info)
+           :port    (.getPort info)}))
+      (finally
+        (future
+          (.close mdns-service))))))
+
 (defn socket [host port]
   (let [socket (Socket. host port)
         in     (io/reader socket)

          [bonjour-name endpoint] (discover-and-choose-device (:choose-first-discovered (:options repl-env)) opts)
          endpoint-address (.getHostAddress (:address endpoint))
          endpoint-port (:port endpoint)
          webdav-mount-point (mount-webdav repl-env bonjour-name endpoint-address endpoint-port)
          output-dir (io/file webdav-mount-point)
          env (ana/empty-env)
          core (io/resource "cljs/core.cljs")]
      ((println-fn opts) "\nConnecting to" (bonjour-name->display-name bonjour-name) "...\n")
      (set-up-socket repl-env opts endpoint-address (dec endpoint-port))
      (when (= "true" (:value (jsc-eval repl-env "typeof cljs === 'undefined'")))

    (tear-down repl-env)))

(defn repl-env* [options]
  (JscEnv. (atom nil) (atom nil) (atom nil) (atom nil) options))

(defn repl-env
  [& {:as options}]
