Created
January 6, 2021 12:48
-
-
Save zerothabhishek/4226733197ed5b55ee5ce8ce93b783d9 to your computer and use it in GitHub Desktop.
Revisions
-
zerothabhishek created this gist
Jan 6, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ 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) } }