           [bonjour-name endpoint] (discover-and-choose-device (:choose-first-discovered (:options repl-env)) opts)
           endpoint-address (.getHostAddress (:address endpoint))
           endpoint-port (:port endpoint)
+          _ (reset! (:bonjour-name repl-env) bonjour-name)
           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")]
+          core (io/resource "cljs/core.cljs")
+          reconnect-fn (partial reconnect repl-env opts)]
       ((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) options))

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

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