-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error handling on disconnect #38
Comments
Hello! Looking into this right now. Basically, it has to do with how the underlying library we use works. Basically, unless libwebsockets gets an official "close" from a server (a "clean" close event like someone manually closing the connection), it doesn't fire an event. It does, however, give you options for setting up the client with a timeout. I need to do a bit of an overhaul to the ClientOptions to get this integrated, but if you'd like to test it now, add the following lines to around line 99 in Client.cpp:
The bad news is that the timeouts are in seconds... So for me it took about 5 seconds (on OS X) to get a "close" event from turning my network off. You may be able to play with |
nice. i will try that tomorrow and report back. |
i tried it but nothing happened. no onClose or anything else got called. i placed it in bool Client::connect ( ClientOptions options ) right after: |
Yep, that's the right spot. Hm! What platform are you on? And what are you doing to spark the "onClose"? I was able to get it to fire by turning off my network, but it did take quite some time to do so. Not sure the best way to make it any faster. If you change line 50 in Util.h from You'll get a printout of all of the libwebsockets events. Try setting that then doing your test again; after 30-60 seconds you should see |
just to note that with your original suggestion i do get reconnected successfully once i replug my ethernet cable. so, that helps a lot already. ok will try you latest advice too. |
About to push ability to set these params via ClientOptions. However, libwebsockets uses whatever your system defaults are on OpenBSD platforms (e.g. OS X). Setting "ka_time" to anything but 0 will at least check if alive periodically, but at whatever your global settings are. On my machine (OS X 10.9.4), that timeout is about 30 seconds! |
i am trying to figure out how to catch my client getting disconnected from the server. for example when i unplug the ethernet cable onClose is not called. an onError would be great :)
i should mention that my client only listens to incoming messages.
i tried if(client.getConnection() == false) but this only is set to false if the network connection is not present before and right at start of app.
thanks, stephan
The text was updated successfully, but these errors were encountered: