Created
May 2, 2010 03:31
-
-
Save scottgonzalez/386871 to your computer and use it in GitHub Desktop.
This file contains 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 http = require("http"), | |
querystring = require("querystring"), | |
sys = require("sys"); | |
var channel = "http://chat.nodejitsu.com/chat", | |
speed = 5000, | |
spammers = 10; | |
for (var i = 0; i < spammers; i++ ) { | |
setTimeout(startSpamming, (speed / spammers) * i); | |
} | |
function startSpamming() { | |
var nick = "spammer" + Math.floor((Math.random() * 10000)); | |
http.cat(channel + "/join?" + querystring.stringify({ nick: nick}), function(status, content) { | |
sys.puts("joined: " + sys.inspect(content)); | |
var id = JSON.parse(content).id, | |
count = 0; | |
var interval = setInterval(function() { | |
var query = querystring.stringify({ | |
id: id, | |
text: "spamming the chat " + (++count) | |
}); | |
http.cat(channel + "/send?" + query); | |
sys.print("."); | |
if (!(count % 50)) { | |
sys.print("\n"); | |
} | |
}, speed); | |
process.addListener("SIGINT", function() { | |
http.cat(channel + "/part?" + querystring.stringify({ id: id }), function() { | |
clearInterval(interval); | |
sys.puts("\nSent " + count + " messages."); | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
script to spam a node-chat server, used for load testing