Skip to content

Instantly share code, notes, and snippets.

@zerothabhishek
Created January 6, 2021 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerothabhishek/4226733197ed5b55ee5ce8ce93b783d9 to your computer and use it in GitHub Desktop.
Save zerothabhishek/4226733197ed5b55ee5ce8ce93b783d9 to your computer and use it in GitHub Desktop.
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