We're updating the issue view to help you get more done. 

Clojure socket server

Description

Programs often want to provide REPLs to users in contexts when a) network communication is desired, b) capturing stdio is difficult, or c) when more than one REPL session is desired. In addition, tools that want to support REPLs and simultaneous conversations with the host are difficult with a single stdio REPL as currently provided by Clojure.

Tooling and users often need to enable a REPL on a program without changing the program, e.g. without asking author or program to include code to start a REPL host of some sort. Thus a solution must be externally and declaratively configured (no user code changes). A REPL is just a special case of a socket service. Rather than provide a socket server REPL, provide a built-in socket server that composes with the existing repl function.

For design background, see: http://dev.clojure.org/display/design/Socket+Server+REPL

Start a socket server by supplying an extra system property (classpath and clojure.main here, but this would generally be starting your own app instead - we won't use the repl it starts):

1 java -cp target/classes -Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}" clojure.main

where options are:

  • address = host or address, defaults to loopback

  • port = port, required

  • accept = namespaced function to invoke on socket accept, required

  • args = sequential collection of args to pass to accept

  • bind-err = defaults to true, binds err to out stream

  • server-daemon = defaults to true, socket server thread doesn't block exit

  • client-daemon = defaults to true, socket client threads don't block exit

Run a repl client using telnet:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 $ telnet 127.0.0.1 5555 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. user=> (println "hello") hello nil user=> clojure.core.server/*session* {:server "repl", :client "1"} user=> (ns foo) nil foo=> (+ 1 1) 2 foo=>

Patch: clj-1671-13.patch

Environment

None

Status

Assignee

Alex Miller

Reporter

Alex Miller

Labels

Approval

Ok

Patch

Code and Test

Fix versions

Affects versions

Release 1.7

Priority

Major