The following code is used in {{src/clj/clojure/core/server.clj}} to validate whether a port number is valid:
(defn- validate-opts
"Validate server config options"
[{:keys [name port accept] :as opts}]
(doseq [prop [:name :port :accept]] (required opts prop))
(when (or (not (integer? port)) (not (< -1 port 65535)))
(throw (ex-info (str "Invalid socket server port: " port) opts))))
However this is very slightly incorrect, since port 65535 is excluded but it is actually a valid port.
`
user=> (defn is-invalid-port [port] (or (not (integer? port)) (not (< -1 port 65535))))
'user/is-invalid-port
user=> (is-invalid-port 65534)
false
user=> (is-invalid-port 65535) ; should be false!
true
user=> (is-invalid-port 65536)
true
`
This is corroborated by (link: https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html#ServerSocket(int) text: {{ServerSocket}}'s Javadoc):
{quote}
IllegalArgumentException - if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
{quote}
Patch: port-65535-obo-v2.patch
Prescreened: Alex Miller