Java-based Telnet proxy server with TLS support. But why java.net.SocketException: Connection refused

Viewed 159

I need you to write the "3270 Proxy" server. 3270 is a specific Telnet protocol We will use commercially available Telnet clients and Telnet servers with our custom Telnet proxy my code needs to listen on 127.0.0.1 port 8080 for this connection when it receives a connection, it needs to relay that connection to ezrad.com port 23 any response from ezrad.com port 23 needs to be relayed back to this TN5250 client

package telnetproxyserver;

/**
 * Suvonkar Kundu
 */
public class KeyWord {

    public static final String socksProxyHost = "127.0.0.1";
    public static final String socksProxyPort = "8080";
    public static final String host = "ezrad.com";
    public static final int port = 23;
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telnetproxyserver;

import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import javax.net.ssl.SSLSocketFactory;
import org.apache.commons.net.telnet.TelnetClient;

/**
 *
 * @author Suvonkar Kundu
 */
public class TelnetProxyServer {

    public static PrintStream psout;

    static void write(String value) {
        try {
            psout.println(value);
            psout.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void TelnetProxySreverConector() {

        TelnetClient telnet;

        try {
            // 1. Create the TelnetClient Object 
            telnet = new TelnetClient();

            // 2. Set up our own SocketFactory (For SSL)
            SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
            telnet.setSocketFactory(sslsocketfactory);

            // 3. Set the proxy
            System.setProperty("socksProxyHost", KeyWord.socksProxyHost);
            System.setProperty("socksProxyPort", KeyWord.socksProxyPort);

            Proxy socksProxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(KeyWord.socksProxyHost, Integer.parseInt(KeyWord.socksProxyPort)));
            telnet.setProxy(socksProxy);

            // 4. Connect
            telnet.connect(KeyWord.host, KeyWord.port);
            Thread.sleep(1000);



            // 6. Address the output stream
            String r;
            psout = new PrintStream(telnet.getOutputStream());
            Thread.sleep(1000);
         // <- r is null!!

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
     TelnetProxySreverConector();
    }
}

But throw exception java.net.SocketException: Connection refused connect telnet server throw telnet proxy server
Please help anyone.

0 Answers
Related