Skip to content

TCP Socket Connection Techniques

Gary Russell edited this page Nov 6, 2013 · 2 revisions

Various extension points are provided on the TCP connection factories. An example of how to use a custom TcpSocketFactorySupport to bind to a local interface/port is shown in this Gist

A similar technique can be used to apply a connect timeout to the socket...

@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
	Socket socket = this.delegate.createSocket();
	socket.connect(new InetSocketAddress(host, port), 1000);
	return socket;
}

... just use a similar TcpSocketFactorySupport to that shown in the gist, with this modified method.