As far as I know it's pretty tricky to change that setting. There's nothing built into the underlying SocketChannel that allows tweaking the connection parameter.
The standard solution is to start a thread or similar which waits the desired delay time and then checks if the connection finished. If it did, then fine, otherwise it forces a close of the connection.
Using the bundled EventMachine is a way to do this:
EventMachine eventMachine = new EventMachine();
eventMachine.start();
final NIOSocket nioSocket = eventMachine.getNIOService().openSocket(ipAddress, networkPort);
final DelayedEvent timeoutEvent = eventMachine.executeLater(10000, new Runnable()
{
public void run()
{
System.out.println("Connection timeout!");
nioSocket.close();
}
}
nioSocket.listen(new SocketObserverAdapter()
{
public void connectionOpened(NIOSocket nioSocket)
{
timeoutEvent.cancel();
System.out.println("Connection opened ok.")
}
});