Skip to content

Instantly share code, notes, and snippets.

@pushkarnk
Last active July 15, 2019 06:01
Show Gist options
  • Save pushkarnk/b63275f98acfe86d6251074c54e6dc9c to your computer and use it in GitHub Desktop.
Save pushkarnk/b63275f98acfe86d6251074c54e6dc9c to your computer and use it in GitHub Desktop.
const WebSocket = require('ws');
for (i=0; i < 50; i++) {
let ws = this.ws = new WebSocket("ws://localhost:9001/");
ws.onopen = (event) => {
console.log("Websocket opened");
ws.send("This is the first message that was sent");
ws.send("This is the second message that was sent");
};
ws.on('message', function incoming(data) {
console.log(data);
});
setTimeout(function(i) {
ws.close()
}, 5000 + i*1000);
ws.onclose = (event) => {
console.log("WebSocket closed")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment