extract makeInetSocketAddress (by hostname) in SocketClient (#509)

to allow overriding with InetSocketAddress.createUnresolved for use with proxy

Co-authored-by: Jeroen van Erp <jeroen@hierynomus.com>
This commit is contained in:
Meteorite
2020-02-20 11:04:39 +03:00
committed by GitHub
parent 241c355e20
commit d09276fe01

View File

@@ -53,6 +53,10 @@ public abstract class SocketClient {
this.defaultPort = defaultPort; this.defaultPort = defaultPort;
} }
protected InetSocketAddress makeInetSocketAddress(String hostname, int port) {
return new InetSocketAddress(hostname, port);
}
/** /**
* Connect to a host via a proxy. * Connect to a host via a proxy.
* @param hostname The host name to connect to. * @param hostname The host name to connect to.
@@ -83,7 +87,7 @@ public abstract class SocketClient {
} else { } else {
socket = new Socket(proxy); socket = new Socket(proxy);
} }
socket.connect(new InetSocketAddress(hostname, port), connectTimeout); socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
onConnect(); onConnect();
} }
@@ -131,7 +135,7 @@ public abstract class SocketClient {
this.hostname = hostname; this.hostname = hostname;
this.port = port; this.port = port;
socket = socketFactory.createSocket(); socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(hostname, port), connectTimeout); socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
onConnect(); onConnect();
} }
} }
@@ -144,7 +148,7 @@ public abstract class SocketClient {
this.port = port; this.port = port;
socket = socketFactory.createSocket(); socket = socketFactory.createSocket();
socket.bind(new InetSocketAddress(localAddr, localPort)); socket.bind(new InetSocketAddress(localAddr, localPort));
socket.connect(new InetSocketAddress(hostname, port), connectTimeout); socket.connect(makeInetSocketAddress(hostname, port), connectTimeout);
onConnect(); onConnect();
} }
} }