Java Sockets Taking too long to timeout

I have had this problem of sockets taking way too long to timeout when the specified ip address is invalid. Even setting the timeout appropriately and catching the errors I have still seen the execution of creating a socket take appox 10 times as long as it "should" have using the timeout being set to some abritray number.

Is there anyway to check and see if a certain IP has a specified port open, besides trying to connect to it by creating a socket and waiting for the very long timeout to occur.

I have tried using a loop of isReachable's and nesting in an attempt to connect to the certain port using a socket. I would like to know if there was a different way of implementing this. Also if the incredibly long wait that occurs from an invalid ip using a socket is normal.

[801 byte] By [Smf9835a] at [2007-10-2 15:14:35]
# 1
Hi,If your IP stack is IPV6 enabled you may experience strange problems like this, should be corrected in Java6Beta
mdentya at 2007-7-13 14:15:33 > top of Java-index,Java Essentials,Java Programming...
# 2
Would using an IPv4 address affect the IP stack setting? Or are you talking about something that is outside the realm of a code fix that I can accomplish?
Smf9835a at 2007-7-13 14:15:33 > top of Java-index,Java Essentials,Java Programming...
# 3
http://forum.java.sun.com/thread.jspa?threadID=598025&tstart=0
baftosa at 2007-7-13 14:15:33 > top of Java-index,Java Essentials,Java Programming...
# 4

So the best approach so far seams to be

For Loop

Test for .isReachable(ip)

if there then Test for socket(port)

If I use this in a multithreaded system it should be pretty fast, however this is still taking about 4.5 seconds per ip. Does this seam like a reasonable time?

Smf9835a at 2007-7-13 14:15:33 > top of Java-index,Java Essentials,Java Programming...