Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Normal
Listening vs connectingIf 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
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