isapir / lucee-websocket

Enables server WebSockets for Lucee via JSR-356 compliant servlet containers (e.g. Tomcat 8, Jetty 9.1, etc.)
GNU Lesser General Public License v2.1
17 stars 6 forks source link

ping/pong mechanism to keep the websocket open #25

Open artknight opened 3 years ago

artknight commented 3 years ago

@isapir I am trying to implement a ping/pong mechanism. The issue with using sleep() is that it pauses the entire websocket from listening ( no onMessage events get caught )

private function _ping(websocket){
        //returns true if the connection is open, else false
        if (arguments.websocket.sendText("ping")){
            sleep(20000);
            this._ping(arguments.websocket);
        }
    }

even tried using threads

private function _ping(websocket){
        //returns true if the connection is open, else false
        if (arguments.websocket.sendText("ping")){
            thread {
                sleep(20000);
                _ping(arguments.websocket);
            }
        }
    }

using thread i do not get the recursive behavior for some reason. Does anyone have any suggestions/ideas?