Reply to thread

Listening vs connecting


If a connection attempt fails, it is logical for a socket to throw an exception. Comparing a listening socket with a connecting socket is misleading - listening for connections is a passive operation, whereas connecting is an active operation with (essentially) immediate results.


There are a number of reasons a connection attempt could fail, and you should check this (using SocketException.ErrorCode for example), before deciding whether to attempt another connection, or to perform some other action. Conversely, a listening socket doesnt even throw SocketExceptions once it has started listening - it is waiting for something to happen.


If you feel that you really must have this behaviour, then implementing a loop as you have done, with a short wait between attempts, is probably the easiest solution.


Good luck :)


Back
Top