gpt4 book ai didi

java - Apache Mina SSHD 1.0 服务器立即退出

转载 作者:行者123 更新时间:2023-11-30 08:43:21 24 4
gpt4 key购买 nike

我正在使用 Apache Mina sshd-core-1.0.0 启动 SFTP 守护进程。然而,程序在 sshd.start() 之后退出。没有错误。但是,如果我使用 sshd-core-0.0.14,服务器启动正常,我可以启动 SFTP session 。我是否遗漏了 1.0.0 的某些内容?

1.0.0 的代码片段(不工作)

public static void main(String[] args) throws IOException {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2222);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File ("hostkey.ser")))
sshd.setPasswordAuthenticator(new AuthenticatorImpl());
sshd.start();
}

带有 0.0.14 的代码片段(有效)

public static void main(String[] args) throws IOException {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2222);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
sshd.setPasswordAuthenticator(new AuthenticatorImpl());
sshd.start();
}

1.0.0运行时输出如下。代码开始正常,但在 sshd.start() 语句之后终止。

2015-12-16 19:57:38,510 DEBUG SFTPServer.main(SFTPServer.java:26) message
2015-12-16 19:57:38,767 INFO org.apache.sshd.common.util.SecurityUtils$BouncyCastleRegistration.call(SecurityUtils.java:145) Trying to register BouncyCastle as a JCE provider
2015-12-16 19:57:39,076 INFO org.apache.sshd.common.util.SecurityUtils$BouncyCastleRegistration.call(SecurityUtils.java:149) Registration succeeded
2015-12-16 19:57:39,105 DEBUG org.apache.sshd.common.io.nio2.Nio2Acceptor.bind(Nio2Acceptor.java:57) Binding Nio2Acceptor to address 0.0.0.0/0.0.0.0:2222
2015-12-16 19:57:39,114 INFO SFTPServer.main(SFTPServer.java:32) Started

最佳答案

SshServer.Start 只开始监听传入端口。它不会阻塞。所以 main 之后立即终止。这在 0.0.14 中应该没有任何不同,尽管我无法尝试。

您必须明确地在 main 中等待以保持服务器运行。

查看 SshServer.main 是如何实现的(在 0.0.14 和 1.0.0 中):

public static void main(String[] args) throws Exception {

...

SshServer sshd = SshServer.setUpDefaultServer();

...

sshd.start();

Thread.sleep(Long.MAX_VALUE);
}

关于java - Apache Mina SSHD 1.0 服务器立即退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34324964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com