Created
January 6, 2021 12:48
-
-
Save zerothabhishek/4226733197ed5b55ee5ce8ce93b783d9 to your computer and use it in GitHub Desktop.
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
const WebSocket = require('ws'); | |
const URL = "ws://ws.example.org:8080/cable" | |
const ORIGIN = "https://example.org" | |
function connect(label) { | |
const ws = new WebSocket(URL, [], { origin: ORIGIN }) | |
ws.on('open', function open() { | |
console.log("~~~> Connected", label) | |
}) | |
ws.on('message', function incoming(data) { | |
console.log("~~~>", label, data) | |
}) | |
ws.on('close', function close() { | |
console.log('~~~~> disconnected', label) | |
}) | |
} | |
function simulateOne(iteration) { | |
const label = "test-" + iteration | |
connect(label) | |
} | |
function simulate(num) { | |
for (var i = 0; i < num; i++) { | |
(function(iteration) { simulateOne(iteration) })(i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment