Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Connectivity Socket Factory
package my.infrastructure;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.SocketFactory;
// service connection based on CFServiceFacade class https://gist.github.com/niklas1375/01254bcee0fb90a33e02c9ae1aca9701
import my.util.ConnectivityService;
public class ConnectivitySocketFactory extends SocketFactory {
private ConnectivityService conn = new ConnectivityService();
private String locationId;
public ConnectivitySocketFactory(String locationId) {
this.locationId = locationId;
}
@Override
public Socket createSocket() throws IOException {
return conn.getProxy(locationId);
}
@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
return conn.getProxy(locationId);
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
throws IOException, UnknownHostException {
return conn.getProxy(locationId);
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return conn.getProxy(locationId);
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
throws IOException {
return conn.getProxy(locationId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment