英文:
How to connect to a locally running REPL via Leiningen?
问题
我有一个Spring Boot应用程序,在其中创建一个REPL,就像在这个答案中所示。
也就是说,我有以下代码:
@Service
public class ClojureRepl {
private final Logger logger = LoggerFactory.getLogger("CLOJURE");
@PostConstruct
public void init() {
final IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read(MAIN_CLOJURE_NAMESPACE));
Clojure.var("clojure.core.server", "start-server").invoke(
Clojure.read("{:port 5555 :name spring-repl :accept clojure.core.server/repl}")
);
}
@PreDestroy
public void destroy() {
Clojure.var("clojure.core.server", "stop-server").invoke(
Clojure.read("{:name spring-repl}")
);
}
}
当我启动应用程序并在命令行上输入 nc localhost 5555
时,我能够连接到该REPL。
我想尝试使用nRepl作为客户端。
因此,我尝试输入
lein repl :connect 127.0.0.1:5555
它只会输出
Connecting to nREPL at 127.0.0.1:5555
然后什么都不会发生。
我如何使用 lein repl
连接到服务器的REPL?
英文:
I have a Spring Boot application in which I create a REPL as shown in this answer.
That is, I have the following code:
@Service
public class ClojureRepl {
private final Logger logger = LoggerFactory.getLogger("CLOJURE");
@PostConstruct
public void init() {
final IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read(MAIN_CLOJURE_NAMESPACE));
Clojure.var("clojure.core.server", "start-server").invoke(
Clojure.read("{:port 5555 :name spring-repl :accept clojure.core.server/repl}")
);
}
@PreDestroy
public void destroy() {
Clojure.var("clojure.core.server", "stop-server").invoke(
Clojure.read("{:name spring-repl}")
);
}
}
When I start the application and enter nc localhost 5555
on the command line, I am able to connect to that REPL.
I want to try out using nRepl as a client.
So, I tried entering
lein repl :connect 127.0.0.1:5555
It only outputs
Connecting to nREPL at 127.0.0.1:5555
and then nothing happens.
How can I connect to the server REPL using lein repl
?
答案1
得分: 2
内置的Clojure服务器在clojure.core.repl中只启动一个带有纯文本协议的套接字服务器,这就是为什么它与telnet很好地配合使用。
Leiningen使用nREPL协议。如果你想使用它,请尝试使用nREPL库打开服务器,使用nrepl.server/start-server
。
英文:
The built-in Clojure server in clojure.core.repl just starts a socket server with a plain text protocol, this is why it works well with telnet.
Leiningen uses the nREPL protocol. If you want to use it, try opening the server using the nREPL library with nrepl.server/start-server
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论