Package org.apache.sshd.client

Examples of org.apache.sshd.client.SshdSocketAddress


    public ChannelDirectTcpip(SshdSocketAddress local, SshdSocketAddress remote) {
        super("direct-tcpip");
        if (local == null) {
            try {
                local = new SshdSocketAddress(InetAddress.getLocalHost().getHostName(), 0);
            } catch (UnknownHostException e) {
                throw new IllegalStateException("Unable to retrieve local host name");
            }
        }
        if (remote == null) {
View Full Code Here


    @Test
    public void testRemoteForwardingNative() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress remote = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress local = new SshdSocketAddress("localhost", echoPort);

        session.startRemotePortForwarding(remote, local);

        Socket s = new Socket(remote.getHostName(), remote.getPort());
        s.getOutputStream().write("Hello".getBytes());
View Full Code Here

    @Test
    public void testLocalForwardingNative() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress local = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress remote = new SshdSocketAddress("localhost", echoPort);

        session.startLocalPortForwarding(local, remote);

        Socket s = new Socket(local.getHostName(), local.getPort());
        s.getOutputStream().write("Hello".getBytes());
View Full Code Here

    @Test
    public void testForwardingChannel() throws Exception {
        ClientSession session = createNativeSession();

        int forwardedPort = getFreePort();
        SshdSocketAddress local = new SshdSocketAddress("", forwardedPort);
        SshdSocketAddress remote = new SshdSocketAddress("localhost", echoPort);

        ChannelDirectTcpip channel = session.createDirectTcpipChannel(local, remote);
        channel.open().await();

        channel.getOut().write("Hello".getBytes());
View Full Code Here

        }
    }

    @Override
    public void sessionCreated(final IoSession session) throws Exception {
        SshdSocketAddress remote = forwards.get(((InetSocketAddress) session.getLocalAddress()).getPort());
        final ChannelForwardedTcpip channel = new ChannelForwardedTcpip(session, remote);
        session.setAttribute(ChannelForwardedTcpip.class, channel);
        this.session.registerChannel(channel);
        channel.open().addListener(new SshFutureListener<OpenFuture>() {
            public void operationComplete(OpenFuture future) {
View Full Code Here

        int originatorPort = buffer.getInt();
        log.info("Receiving request for direct tcpip: hostToConnect={}, portToConnect={}, originatorIpAddress={}, originatorPort={}",
                new Object[] { hostToConnect, portToConnect, originatorIpAddress, originatorPort });

        final ClientSessionImpl clientSession = (ClientSessionImpl)getSession();
        SshdSocketAddress address;
        try {
            address = clientSession.getForwardedPort(portToConnect);
        } catch (RuntimeException e) {
            address = null;
        }
        //final ForwardingFilter filter = clientSession.getClientFactoryManager().getForwardingFilter();
        if (address == null /*|| filter == null || !filter.canConnect(address, serverSession)*/) {
            super.close(true);
            f.setException(new OpenChannelException(SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, "connect denied"));
            return f;
        }

        connector = new NioSocketConnector();
        out = new ChannelOutputStream(this, remoteWindow, log, SshConstants.Message.SSH_MSG_CHANNEL_DATA);
        IoHandler handler = new IoHandlerAdapter() {
            @Override
            public void messageReceived(IoSession session, Object message) throws Exception {
                IoBuffer ioBuffer = (IoBuffer) message;
                int r = ioBuffer.remaining();
                byte[] b = new byte[r];
                ioBuffer.get(b, 0, r);
                out.write(b, 0, r);
                out.flush();
            }

            @Override
            public void sessionClosed(IoSession session) throws Exception {
                if (!closing) {
                    sendEof();
                }
            }
        };
        connector.setHandler(handler);
        ConnectFuture future = connector.connect(address.toInetSocketAddress());
        future.addListener(new IoFutureListener<ConnectFuture>() {
            public void operationComplete(ConnectFuture future) {
                if (future.isConnected()) {
                    ioSession = future.getSession();
                    f.setOpened();
View Full Code Here

TOP

Related Classes of org.apache.sshd.client.SshdSocketAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.