EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Java - problems with dynamic port forwarding

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
Posted: 05/20/2014 11:34:59
by  Max
Hello, I am trying to use SecureBlackbox to do dynamic port forwarding. However, I cannot seem to be able to create a local SOCKS server. Here is my code:

        TElSSHLocalPortForwarding Client;
        int SSHPort, forwardedPort;
        String host, username, password;
        Client = null;
        SSHPort = 22;
        forwardedPort = 9150;
        host = "<SSH server>";
        username = "<login>";
        password = "<password>";
        try {
            Client = new TElSSHLocalPortForwarding();


            Client.SetOnKeyValidate(new TSSHKeyValidateEvent(new TSSHKeyValidateEvent.Callback() {
                public boolean TSSHKeyValidateEventCallback(TObject arg0, TElSSHKey arg1) {
                    System.out.println("Server key received");
                    return true;
        } catch (Exception exc) {
            System.out.println("BlackBox SSH: " + exc.toString());

        BufferedReader reader;
        try {
            HttpsURLConnection con = connectFunctions.request("https://google.com", "GET", null, "", null, "", connectFunctions.connectToProxy("" + forwardedPort, "socks"));
            reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            for (String line; (line = reader.readLine()) != null;){
        } catch (java.io.IOException exc) {
            System.out.println("Connection: " + exc.toString());

As you see, I'm trying to create a dynamic port forwarding connection to the server and then connect to the created local SOCKS port to with HttpsURLConnection. However, this doesn't work. It seems that the SOCKS server wasn't up. The error gets thrown up in the second try block on reader = new BufferedReader(new InputStreamReader(con.getInputStream())); and it is java.net.SocketException: Connection refused: connect.
Any clue on what might be wrong with my code? I thought I followed the sample code more or less well... =(
Posted: 05/20/2014 11:49:09
by Eugene Mayevski (EldoS Corp.)

We don't sell our software to russia.

Sincerely yours
Eugene Mayevski



Topic viewed 365 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!