IOException after Socket.connect()

A

alessandro

Hi, I have a problem calling connect(): it throws an IOException. The server
has not already started, but I setted a long timeout. Does the socket fail
just because it doesnt find the server, or does it wait till timeout has
elapsed?
 
G

Gordon Beaton

Hi, I have a problem calling connect(): it throws an IOException.
The server has not already started, but I setted a long timeout.
Does the socket fail just because it doesnt find the server, or does
it wait till timeout has elapsed?

The timeout doesn't mean "wait this long until there is a server to
connect to" it means "wait at most this long before reporting
failure". Of course if the attempt fails or succeeds before that, it
will return sooner.

If the host is running and reachable from your client host, but there
is no listening server, connect() will fail more or less immediately.
The remote OS will refuse the connection attempt, at which point
connect() has done all it can do.

If you want to continue trying until the server process comes up,
have your application sleep for a while before trying again.

/gordon
 
A

alessandro

The timeout doesn't mean "wait this long until there is a server to
connect to" it means "wait at most this long before reporting
failure". Of course if the attempt fails or succeeds before that, it
will return sooner.

Uh, I thought this was the meaning. I'm not an expert in network
programming...
If the host is running and reachable from your client host, but there
is no listening server, connect() will fail more or less immediately.
The remote OS will refuse the connection attempt, at which point
connect() has done all it can do.

In fact it failed immediately.
If you want to continue trying until the server process comes up,
have your application sleep for a while before trying again.

Ok, now it works! Thank you!

Alessandro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top