Simple-WebSocket-Server icon indicating copy to clipboard operation
Simple-WebSocket-Server copied to clipboard

Acting on a failed connect()

Open rberlich opened this issue 9 years ago • 3 comments

Hi again,

from what I understand, the client-side connect() call has the sole option to throw from within the onerror() call to let the audience know that something went wrong. Any chance of returning a boolean or giving access to the error code through a reference argument ?

All clients and the server will be started in a compute cluster in my case, usually through some submission script and via a batch queue. It is not guaranteed that the server is available immediately. Hence I'd like to loop on the connect() call for a number of times on the client side, so the server has time to start up.

This would be easiest if connect() would return a bool, something like

while(!connect() && nConnectionAttempts++ < maxConnectionAttempts);

Thanks and Best Regards, Beet

rberlich avatar Nov 28 '16 12:11 rberlich

Hmmm, o.k., connect() is usually not called directly, instead one uses start(). However, this also returns void, so a loop would not be possible.

rberlich avatar Nov 28 '16 12:11 rberlich

You would have to perform this check in onerror, and run Client::start again after an error is received.

eidheim avatar Nov 28 '16 12:11 eidheim

In your case, you probably have to call Client::stop before calling Client::start again.

eidheim avatar Nov 28 '16 12:11 eidheim