RSS Feed

Lisp Project of the Day


You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.


Tests ๐Ÿคจ
CI ๐Ÿ˜€

This small utility library allows you to find an open network port or to probe if the port is open.

It is useful when you need to start a server on some free port in a given range:

POFTHEDAY> (find-port:find-port :min 4005)
4005 (12 bits, #xFA5)

;; Now we'll start the netcat process
;; to listen on the 4005 port
POFTHEDAY> (bt:make-thread
            (lambda ()
               "nc -l 4005")))
#<SB-THREAD:THREAD "Anonymous thread" RUNNING {10050A25F3}>

;; Port 4005 is taken now:
POFTHEDAY> (find-port:find-port :min 4005)
4006 (12 bits, #xFA6)

;; This function can be used to check if the port is taken:
POFTHEDAY> (find-port:port-open-p 4005)
POFTHEDAY> (find-port:port-open-p 4006)

Beware, this library considered port is taken only when this port is opened by another process. This is because it uses :reuse-address argument when checking if the port is opened:

(usocket:socket-listen interface port
                       :reuse-address t)

That is it for this Friday. I have to spend some time with my family. Have a nice weekend!

Brought to you by 40Ants under Creative Commons License