   (start [this]
     (if socket-thread
       this
-      (let [sock (doto (ServerSocket. (:port cfg))
-                   (.setSoTimeout 100))
+      (let [sock (doto (ServerSocket. (:port cfg) 0 (InetAddress/getLoopbackAddress))
+                       (.setSoTimeout 100))
             thread (doto (Thread. #(run-server system-atom sock))
                      (.start))]
         (.mkdirs (io/file (:inlein-home cfg)))

              in (-> (.getInputStream client-sock)
                     (BufferedInputStream.)
                     (BencodeReader.))]
    (when-not (.. client-sock getInetAddress isSiteLocalAddress)
      (let [first-op (bencode-read in)]
        (println "first op:" first-op)
        (write-ack out first-op)
        (let [res (handle-request-errors first-op in out)]
          (println res)
          (case res
            ::shutdown (.start (Thread. #(swap! system-atom component/stop)))
            nil))))))

(defn run-server [system-atom server-socket]
  (try

  (:require [com.stuartsierra.component :as component]
            [clojure.java.io :as io]
            [inlein.daemon.read-script :as rs])
  (:import (java.net ServerSocket SocketTimeoutException InetAddress)
           (java.io BufferedInputStream)
           (com.hypirion.bencode BencodeReader BencodeWriter)))

