Transports are roughly analogous to Ring’s adapters: they provide an
implementation of a common protocol (
to enable nREPL clients and servers to send and receive messages without regard
for the underlying channel or particulars of message encoding.
nREPL includes three transports, all of which are socket-based: a "tty"
transport that allows one to connect to an nREPL endpoint using e.g.
(which therefore supports only the most simplistic interactive evaluation of
expressions), one that uses
bencode to encode
nREPL messages over sockets, and one that uses EDN as the data exchange format.
It’s the bencode transport that is used by default by
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)
Afterwards you can simply connect to the server with some TTY client like
$ 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 -R:nrepl -m nrepl.cmdline -t nrepl.transport/tty nREPL server started on port 63266 on host localhost - telnet://localhost:63266
There’s nothing special you have to do to use the bencode transport,
as it’s the default transport for
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.
Keep in mind that nREPL itself doesn’t use this library, as it’s committed to having 0 runtime dependencies.
The code in the library and in nREPL
|The EDN transport was introduced in nREPL 0.7.|
Using the EDN transport is pretty simple. You just need to start an nREPL server with EDN transport and you’re good to go:
(require '[nrepl.server :as server] '[nrepl.transport :as transport]) (server/start-server :port 12345 :transport-fn transport/edn)
You can also start an nREPL with a EDN transport using
$ clj -R:nrepl -m nrepl.cmdline -t nrepl.transport/edn nREPL server started on port 63266 on host localhost - nrepl+edn://localhost:63266
The main difference between the bencode transport and the EDN one is that instead of sending and receiving bencode dictionaries you’d be sending and receiving EDN maps. The structures of the messages is identical, only the data format changes.