Coder Social home page Coder Social logo

Comments (6)

robotconscience avatar robotconscience commented on September 20, 2024

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:

        info.ka_time = 1;
        info.ka_probes = 1;
        info.ka_interval = 1;

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 ka_probes (how many times it tests the network) and ka_interval (time between the checks) to get a more real time response.

from ofxlibwebsockets.

 avatar commented on September 20, 2024

nice. i will try that tomorrow and report back.
thanks a bunch.

from ofxlibwebsockets.

 avatar commented on September 20, 2024

i tried it but nothing happened. no onClose or anything else got called.

i placed it in bool Client::connect ( ClientOptions options )

right after:
info.port = CONTEXT_PORT_NO_LISTEN;
info.protocols = &lws_protocols[0];
info.extensions = libwebsocket_get_internal_extensions();
info.gid = -1;
info.uid = -1;

from ofxlibwebsockets.

robotconscience avatar robotconscience commented on September 20, 2024

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
ofLog( OF_LOG_VERBOSE, getCallbackReason(reason) );
to
ofLog( OF_LOG_ERROR, getCallbackReason(reason) );

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 LWS_CALLBACK_CLOSED, then the onClose event get fired in your main app.

from ofxlibwebsockets.

 avatar commented on September 20, 2024

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.
thanks.

from ofxlibwebsockets.

robotconscience avatar robotconscience commented on September 20, 2024

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!

from ofxlibwebsockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.