diff --git a/src/main/clojure/clojure/tools/nrepl.cljr b/src/main/clojure/clojure/tools/nrepl.cljr index 1738f95..ef40241 100644 --- a/src/main/clojure/clojure/tools/nrepl.cljr +++ b/src/main/clojure/clojure/tools/nrepl.cljr @@ -4,7 +4,7 @@ [clojure.tools.nrepl.server.middleware :as middleware] [clojure.string :as string]) (:import [System.Net Dns IPEndPoint IPAddress] - [System.Net.Sockets TcpListener] )) + [System.Net.Sockets TcpListener AddressFamily] )) (set! *warn-on-reflection* true) @@ -28,11 +28,18 @@ opts (assoc opts :xform (get opts :xform middleware/default-xform)) - host-entry (Dns/GetHostEntry ^String host) - ip-address (first (.AddressList host-entry)) - ip-endpoint (IPEndPoint. ^IPAddress ip-address (int port)) + ;; Calling GetHostEntry with 127.0.0.1 will return all local machine IPs without + ;; the loopback IP, whereas with localhost will return the loopback IP. + host (if (= "127.0.0.1" host) "localhost" host) + host-entry (Dns/GetHostEntry ^String host) + ip-address (->> host-entry + .AddressList + (filter #(= (.AddressFamily ^IPAddress %) + AddressFamily/InterNetwork)) + first) + ip-endpoint (IPEndPoint. ^IPAddress ip-address (int port)) tcp-listener (doto (TcpListener. ip-endpoint) (.Start)) ;; start required here in order to pick up .LocalEndPoint - local-port (.Port ^IPEndPoint (.LocalEndPoint (.Server tcp-listener)))] + local-port (.Port ^IPEndPoint (.LocalEndPoint (.Server tcp-listener)))] (when-not quiet (println (format "Started nREPL server at %s:%d" (.Address ip-endpoint) local-port))) {:socket tcp-listener