Skip to content

ping/pong mechanism to keep the websocket open #25

@artknight

Description

@artknight

@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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions