Created
July 8, 2010 17:30
-
-
Save dshaw/468335 to your computer and use it in GitHub Desktop.
Quick and dirty psuedo-ish code for a Node.js Web Socket connection throttler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var maxThrottles = 10; | |
| connectionManager[connection.id].lastMessage = +new Date(); | |
| connectionManager[connection.id].timeOutUntil = connectionManager[connection.id].lastMessage + 1000; // one second, too long? | |
| connectionManager[connection.id].throttledCount = 0; | |
| connection.addListener("message", function( message ) { | |
| var messageTime = +new Date(); | |
| if (messageTime < connectionManager[connection.id].timeOutUntil) { | |
| (throttleCount < maxThrottles) ? connectionManager[connection.id].throttledCount++ : kickMe(connection.id); | |
| } | |
| // call method on connection manager to update lastMessage and reset derivative values. | |
| // continue handling message | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment