本文整理汇总了Java中org.apache.sshd.server.SshServer.getPort方法的典型用法代码示例。如果您正苦于以下问题:Java SshServer.getPort方法的具体用法?Java SshServer.getPort怎么用?Java SshServer.getPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sshd.server.SshServer
的用法示例。
在下文中一共展示了SshServer.getPort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleHop
import org.apache.sshd.server.SshServer; //导入方法依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHop() throws Exception {
SshServer sshServer = setUpSshServer();
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例2: testSingleHop_EcDsaServer
import org.apache.sshd.server.SshServer; //导入方法依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHop_EcDsaServer() throws Exception {
SshServer sshServer = setUpSshServer(KeyUtils.EC_ALGORITHM);
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例3: testSingleHopWithLocalPort
import org.apache.sshd.server.SshServer; //导入方法依赖的package包/类
@Test(timeout = TEST_TIMEOUT_MILLIS)
public void testSingleHopWithLocalPort() throws Exception {
SshServer sshServer = setUpSshServer();
int sshServerPort = sshServer.getPort();
String hostConfigName = "localhost-" + sshServerPort;
appendToSshFile(CONFIG_FILENAME, "Host " + hostConfigName + "\n\tHostName localhost\n\tPort " + sshServerPort + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect(hostConfigName, "localhost", dummyServerSocketThread.getPort(), 2345);
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(sshServer);
}
}
示例4: doTestTwoHops
import org.apache.sshd.server.SshServer; //导入方法依赖的package包/类
private void doTestTwoHops(String proxyConfiguration) throws Exception {
SshServer firstSshServer = setUpSshServer();
int firstServerPort = firstSshServer.getPort();
SshServer secondSshServer = setUpSshServer();
int secondServerPort = secondSshServer.getPort();
appendToSshFile(CONFIG_FILENAME, "Host firsthop\n\tHostName localhost\n\tPort " + firstServerPort + "\n\n");
appendToSshFile(CONFIG_FILENAME, "Host secondhop\n\tHostName localhost\n\tPort " + secondServerPort + "\n\t" + proxyConfiguration + "\n\n");
try (DummyServerSocketThread dummyServerSocketThread = new DummyServerSocketThread(TRANSFER_CHARSET, TEST_TEXT);
SshProxy sshProxy = new SshProxy()) {
int port = sshProxy.connect("secondhop", "localhost", dummyServerSocketThread.getPort());
final String receivedText;
try (Socket s = new Socket(SshProxy.LOCALHOST, port);
InputStream is = s.getInputStream()) {
log.info("connected to port: {}", port);
receivedText = readLine(is);
}
assertEquals(TEST_TEXT, receivedText);
} finally {
tryStop(firstSshServer);
tryStop(secondSshServer);
}
}
示例5: setUpSshServer
import org.apache.sshd.server.SshServer; //导入方法依赖的package包/类
private SshServer setUpSshServer(String algorithm) throws IOException {
SshServer sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(0);
AbstractGeneratorHostKeyProvider hostKeyProvider = SecurityUtils.createGeneratorHostKeyProvider(getServerKeyFile(algorithm));
hostKeyProvider.setAlgorithm(algorithm);
if (algorithm.equals(KeyUtils.EC_ALGORITHM)) {
hostKeyProvider.setKeySize(256);
}
sshServer.setKeyPairProvider(hostKeyProvider);
sshServer.setPublickeyAuthenticator(AcceptAllPublickeyAuthenticator.INSTANCE);
sshServer.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
writeFingerprintToKnownHosts(algorithm);
sshServer.start();
int sshServerPort = sshServer.getPort();
assertTrue(sshServerPort > 0);
return sshServer;
}