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


Java ChannelDirectTcpip类代码示例

本文整理汇总了Java中org.apache.sshd.client.channel.ChannelDirectTcpip的典型用法代码示例。如果您正苦于以下问题:Java ChannelDirectTcpip类的具体用法?Java ChannelDirectTcpip怎么用?Java ChannelDirectTcpip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelDirectTcpip类属于org.apache.sshd.client.channel包,在下文中一共展示了ChannelDirectTcpip类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testForwardingChannel

import org.apache.sshd.client.channel.ChannelDirectTcpip; //导入依赖的package包/类
@Test
public void testForwardingChannel() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress local = new SshdSocketAddress("", 0);
        SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);

        try (ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote)) {
            channel.open().verify(9L, TimeUnit.SECONDS);

            String expected = getCurrentTestName();
            byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);

            try (OutputStream output = channel.getInvertedIn();
                 InputStream input = channel.getInvertedOut()) {
                output.write(bytes);
                output.flush();

                byte[] buf = new byte[bytes.length + Long.SIZE];
                int n = input.read(buf);
                String res = new String(buf, 0, n);
                assertEquals("Mismatched data", expected, res);
            }
            channel.close(false);
        }
    }
}
 
开发者ID:termd,项目名称:termd,代码行数:27,代码来源:PortForwardingTest.java

示例2: Tunnel

import org.apache.sshd.client.channel.ChannelDirectTcpip; //导入依赖的package包/类
Tunnel(ServerSocket ss, ChannelDirectTcpip tmp, int bufferSize) {
    this.server = ss;
    this.channel = tmp;
    this.bufferSize = bufferSize;
}
 
开发者ID:NLeSC,项目名称:Xenon,代码行数:6,代码来源:SSHUtil.java

示例3: connect

import org.apache.sshd.client.channel.ChannelDirectTcpip; //导入依赖的package包/类
/**
 * Connect an existing {@link SshClient} to the server at <code>location</code> and authenticate using the given <code>credential</code>.
 *
 * @param adaptorName
 *            the adaptor where this method was called from.
 * @param client
 *            the client to connect.
 * @param location
 *            the server to connect to
 * @param credential
 *            the credential to authenticate with.
 * @param bufferSize
 *            the buffer size used for the (optional) SSH tunnels.
 * @param timeout
 *            the timeout to use in connection setup (in milliseconds).
 * @return the connected {@link ClientSession}
 * @throws XenonException
 *             if the connection setup or authentication failed.
 */
public static SSHConnection connect(String adaptorName, SshClient client, String location, Credential credential, int bufferSize, long timeout)
        throws XenonException {

    if (credential == null) {
        throw new IllegalArgumentException("Credential may not be null");
    }

    if (timeout <= 0) {
        throw new IllegalArgumentException("Invalid timeout: " + timeout);
    }

    if (location == null) {
        throw new IllegalArgumentException("Location may not be null");
    }

    SshdSocketAddress[] locations = extractLocations(adaptorName, location);
    UserCredential[] creds = extractCredentials(adaptorName, locations, credential);

    SSHConnection connection = new SSHConnection(locations.length - 1);

    // Connect to the last location. This is either the destination (without tunneling) or the first hop.
    ClientSession session = connectAndAuthenticate(adaptorName, client, locations[0].getHostName(), locations[0].getPort(), creds[0], timeout);

    try {
        // If we have more that one location we need to tunnel via another location.
        for (int i = 1; i < locations.length; i++) {
            ChannelDirectTcpip channel = session.createDirectTcpipChannel(null, locations[i]);
            channel.open().await(timeout);

            ServerSocket server = new ServerSocket(0);
            int port = server.getLocalPort();

            Tunnel tunnel = new Tunnel(server, channel, bufferSize);
            tunnel.start();

            connection.addHop(i - 1, session, tunnel);

            session = connectAndAuthenticate(adaptorName, client, "localhost", port, creds[i], timeout);
        }

    } catch (IOException e) {
        // Attempt to cleanup the mess
        connection.close();

        try {
            session.close();
        } catch (IOException e1) {
            // ignored
        }

        throw new XenonException(adaptorName, "Failed to set up SSH forwarding", e);

    } catch (XenonException xe) {
        // Attempt to cleanup the mess
        connection.close();
        throw xe;
    }

    connection.setSession(session);
    return connection;
}
 
开发者ID:NLeSC,项目名称:Xenon,代码行数:81,代码来源:SSHUtil.java

示例4: createDirectTcpipChannel

import org.apache.sshd.client.channel.ChannelDirectTcpip; //导入依赖的package包/类
@Override
public ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote)
        throws IOException {
    throw new RuntimeException("Not implemented");
}
 
开发者ID:NLeSC,项目名称:Xenon,代码行数:6,代码来源:MockClientSession.java


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