chickadee » nrepl » nrepl

nrepl port #!optional spawnprocedure

Listen to TCP port port number and (blockingly) wait for incoming connections. (spawn) is called for each incomming connection without arguments where current-input-port, current-output-port and current-error-port are bound to the TCP connection.

You can use spawn, for example, for authentication:

(nrepl 1234
       (lambda ()
         (thread-start! ;; otherwise accept-loop will be blocked
          (lambda ()
            (display ";; please enter an accept token: ")
            (define token (read-line))
            (if (equal? token "abc")
                (begin (print ";; access denied")
                       (close-input-port (current-input-port))
                       (close-output-port (current-output-port))
               (close-output-port (current-error-port))))))))

blockquoteYou can use tcp-addresses and tcp-port-numbers to find out where the new session is coming from.

nrepl will loop for accepting incomming connections unless spawn returns #f.