Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/clojure/clojure/tools/nrepl.cljr
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down