Er, that timeout is for reading, now that I think about it. Maybe this version of connect is the answer: [url=http://java.sun.com/javase/6/docs/api/java/net/Socket.html#connect(java.net.SocketAddress,%20int)]connect(SocketAddress, timeout)[/url]:
Socket s = new Socket(); //note: no args
s.connect(socketAddess, timeout);
...
Aha:
Socket mySocket = new Socket();
//set timeout to 5 seconds
mySocket.setSoTimeout(5000);
InetSocketAddress nextport = new InetSocketAddress(hostname, port);
try {
mySocket.connect(nextport);
} catch (SocketTimeoutException ste) {
ste.printStackTrace();
}
What exactly do you mean by '5 seconds for my client to realize that the server is there'?
> //set timeout to 5 seconds
> mySocket.setSoTimeout(5000);
That's the read timeout, not the connect timeout.
> InetSocketAddress nextport = new InetSocketAddress(hostname, port);
> try {
>mySocket.connect(nextport);
You probably want to supply a connect timeout in this call.