pgriess / node-websocket-client

A Web Socket client for NodeJS
BSD 3-Clause "New" or "Revised" License
150 stars 68 forks source link

Proper implementation of an auto-reconnect? #23

Open ryonlife opened 12 years ago

ryonlife commented 12 years ago

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.