Merge pull request #141 from ziuchkovski/add-proxy-support

Add proxy support for SocketClient/SSHClient
This commit is contained in:
Jeroen van Erp
2015-01-09 14:30:13 +01:00

View File

@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket; import java.net.Socket;
public abstract class SocketClient { public abstract class SocketClient {
@@ -51,12 +52,25 @@ public abstract class SocketClient {
onConnect(); onConnect();
} }
public void connect(InetAddress host, int port, Proxy proxy)
throws IOException {
socket = new Socket(proxy);
socket.connect(new InetSocketAddress(host, port), connectTimeout);
onConnect();
}
public void connect(String hostname, int port) public void connect(String hostname, int port)
throws IOException { throws IOException {
this.hostname = hostname; this.hostname = hostname;
connect(InetAddress.getByName(hostname), port); connect(InetAddress.getByName(hostname), port);
} }
public void connect(String hostname, int port, Proxy proxy)
throws IOException {
this.hostname = hostname;
connect(InetAddress.getByName(hostname), port, proxy);
}
public void connect(InetAddress host, int port, public void connect(InetAddress host, int port,
InetAddress localAddr, int localPort) InetAddress localAddr, int localPort)
throws IOException { throws IOException {
@@ -83,6 +97,16 @@ public abstract class SocketClient {
connect(hostname, defaultPort); connect(hostname, defaultPort);
} }
public void connect(InetAddress host, Proxy proxy)
throws IOException {
connect(host, defaultPort, proxy);
}
public void connect(String hostname, Proxy proxy)
throws IOException {
connect(hostname, defaultPort, proxy);
}
public void disconnect() public void disconnect()
throws IOException { throws IOException {
if (socket != null) { if (socket != null) {