pgriess / node-websocket-client

A Web Socket client for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proper implementation of an auto-reconnect?

ryonlife opened this issue · comments

When a web socket is closed, what's the proper implementation (from a client perspective, not a server) for auto-reconnecting? My thought is something like this, but I wondered if it's too naive, and whether there are any pitfalls I should be aware of.

        connection.on('close', function() {
            reconnect = setInterval(function() {
                // Standard stuff for opening a new WebSocketClient connection
                clearInterval(reconnect);
            }, 1000);
        }); 

Any insights for me? Thanks.