Java Code Examples for org.apache.sshd.common.util.net.SshdSocketAddress#getHostName()

The following examples show how to use org.apache.sshd.common.util.net.SshdSocketAddress#getHostName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteForwardingNative() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress remote = new SshdSocketAddress("", 0);
        SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startRemotePortForwarding(remote, local);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            String expected = getCurrentTestName();
            byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
            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);
        } finally {
            session.stopRemotePortForwarding(remote);
        }
    }
}
 
Example 2
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteForwardingNativeBigPayload() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress remote = new SshdSocketAddress("", 0);
        SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startRemotePortForwarding(remote, local);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            String expected = getCurrentTestName();
            byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
            byte[] buf = new byte[bytes.length + Long.SIZE];

            for (int i = 0; i < 1000; i++) {
                output.write(bytes);
                output.flush();

                int n = input.read(buf);
                String res = new String(buf, 0, n);
                assertEquals("Mismatched data at iteration #" + i, expected, res);
            }
        } finally {
            session.stopRemotePortForwarding(remote);
        }
    }
}
 
Example 3
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalForwardingNative() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress local = new SshdSocketAddress("", 0);
        SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

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

            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);
        } finally {
            session.stopLocalPortForwarding(bound);
        }
    }
}
 
Example 4
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalForwardingNativeBigPayload() throws Exception {
    try (ClientSession session = createNativeSession()) {
        String expected = getCurrentTestName();
        byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
        byte[] buf = new byte[bytes.length + Long.SIZE];

        SshdSocketAddress local = new SshdSocketAddress("", 0);
        SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);
        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            for (int i = 0; i < 1000; i++) {
                output.write(bytes);
                output.flush();

                int n = input.read(buf);
                String res = new String(buf, 0, n);
                assertEquals("Mismatched data at iteration #" + i, expected, res);
            }
        } finally {
            session.stopLocalPortForwarding(bound);
        }
    }
}
 
Example 5
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteForwardingNative() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress remote = new SshdSocketAddress("", 0);
        SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startRemotePortForwarding(remote, local);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            String expected = getCurrentTestName();
            byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
            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);
        } finally {
            session.stopRemotePortForwarding(remote);
        }
    }
}
 
Example 6
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteForwardingNativeBigPayload() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress remote = new SshdSocketAddress("", 0);
        SshdSocketAddress local = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startRemotePortForwarding(remote, local);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            String expected = getCurrentTestName();
            byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
            byte[] buf = new byte[bytes.length + Long.SIZE];

            for (int i = 0; i < 1000; i++) {
                output.write(bytes);
                output.flush();

                int n = input.read(buf);
                String res = new String(buf, 0, n);
                assertEquals("Mismatched data at iteration #" + i, expected, res);
            }
        } finally {
            session.stopRemotePortForwarding(remote);
        }
    }
}
 
Example 7
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalForwardingNative() throws Exception {
    try (ClientSession session = createNativeSession()) {
        SshdSocketAddress local = new SshdSocketAddress("", 0);
        SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);

        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

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

            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);
        } finally {
            session.stopLocalPortForwarding(bound);
        }
    }
}
 
Example 8
Source File: PortForwardingTest.java    From termd with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalForwardingNativeBigPayload() throws Exception {
    try (ClientSession session = createNativeSession()) {
        String expected = getCurrentTestName();
        byte[] bytes = expected.getBytes(StandardCharsets.UTF_8);
        byte[] buf = new byte[bytes.length + Long.SIZE];

        SshdSocketAddress local = new SshdSocketAddress("", 0);
        SshdSocketAddress remote = new SshdSocketAddress(TEST_LOCALHOST, echoPort);
        SshdSocketAddress bound = session.startLocalPortForwarding(local, remote);
        try (Socket s = new Socket(bound.getHostName(), bound.getPort());
             OutputStream output = s.getOutputStream();
             InputStream input = s.getInputStream()) {

            s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));

            for (int i = 0; i < 1000; i++) {
                output.write(bytes);
                output.flush();

                int n = input.read(buf);
                String res = new String(buf, 0, n);
                assertEquals("Mismatched data at iteration #" + i, expected, res);
            }
        } finally {
            session.stopLocalPortForwarding(bound);
        }
    }
}