deleted
Are you talking about connect() or listen()? socket() does not connect to another computer it just creates the file descriptor (socket). Please post your code.
It was connect() time out
Set the socket to non-blocking with fcntl. Set up an FD_SET for the socket, call select() with whatever timeout you like. Reset the socket to non-blocking if you wish, after connect suceeds.
Any reasonable wait time that we should wait for socket connection. I am waiting for 2 secs three tries and if still not connected closing the socket and saying machine not reachable.
Reasonable time is what you think is reasonable. TCP can still operate over pretty slow, high-latency, and lossy connections which is why its timeouts are so ubiquitously and obnoxiously high. Still, 2-3 seconds is not a lot. I've seen connections to web servers etc. take longer than that on occasion, even over highspeed.
I read this somewhere on an Arpanet newsgroup long ago:
If you want a sockets timeout number:
Pick 10 seconds as a base
Pick your users average behavior mode:
screamers 10
impatient 3
quiet, easy going 1
Mutliply the base number x the number in the table above. Use that in your timeval struct for the select() call.
This is meant as joke but timeouts can range up to as high as several minutes, not seconds. I would consider a minimum of 30 seconds.
Thanks Jim, other query is what do we have to correct if socket connection results
"connection refused" though the server is online
---------- Post updated 06-11-10 at 12:25 AM ---------- Previous update was 06-10-10 at 11:38 PM ----------
what would need to correct if connect() call results in "connection refused" thought the server is online