Skip to content

Instantly share code, notes, and snippets.

@apeckham
Last active July 28, 2021 20:54
Show Gist options
  • Save apeckham/78da0a59076a4b91b1f5acf40a96de69 to your computer and use it in GitHub Desktop.
Save apeckham/78da0a59076a4b91b1f5acf40a96de69 to your computer and use it in GitHub Desktop.
find free port in clojure
(defn get-free-port []
(with-open [socket (ServerSocket. 0)]
(.getLocalPort socket)))
@jeff303
Copy link

jeff303 commented Mar 8, 2021

BTW, you can use with-open instead of let to get the close call for free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment