Transports

Transports are roughly analogous to Ring’s adapters: they provide an implementation of a common protocol (nrepl.transport.Transport) to enable nREPL clients and servers to send and receive messages without regard for the underlying channel or particulars of message encoding.

nREPL includes two transports, both of which are socket-based: a "tty" transport that allows one to connect to an nREPL endpoint using e.g. telnet (which therefore supports only the most simplistic interactive evaluation of expressions), and one that uses bencode to encode nREPL messages over sockets. It is the latter that is used by default by nrepl.server/start-server and nrepl.core/connect.

TTY Transport

Using the TTY transport is pretty simple. You just need to start an nREPL server with TTY transport and you’re good to go:

(require
 '[nrepl.server :as server]
 '[nrepl.transport :as transport])

(server/start-server :port 12345 :transport-fn transport/tty :greeting-fn transport/tty-greeting)
The :greeting-fn is responsible for printing the initial message you’ll see upon connecting.

Afterwards you can simply connect to the server with some TTY client like telnet, nc or inf-clojure.

$ nc localhost 12345

;; Clojure 1.9.0
user=>

Starting with nREPL 0.5 you can also start an nREPL with a TTY transport using clj:

$ clj -R:nrepl -m nrepl.cmdline -t nrepl.transport/tty
nREPL server started on port 63266 on host localhost - telnet://localhost:63266

Bencode Transport

There’s nothing special you have to do to use the bencode transport, as it’s the default transport for nrepl.server/start-server.

You’ll need a bencode capable client to connect to an nREPL server that transport.

nREPL’s bencode implementation is available as a standalone library.

The nrepl/bencode library was extracted from nREPL in version 0.4.5. Before this it used to live in the nrepl.bencode namespace.