当前位置: 首页>>代码示例>>Java>>正文


Java SshServer.getPort方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:24,代码来源:SshProxyTest.java

示例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);
	}
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:24,代码来源:SshProxyTest.java

示例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);
	}
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:24,代码来源:SshProxyTest.java

示例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);
	}
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:27,代码来源:SshProxyTest.java

示例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;
}
 
开发者ID:cronn-de,项目名称:ssh-proxy,代码行数:23,代码来源:SshProxyTest.java


注:本文中的org.apache.sshd.server.SshServer.getPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。