Petr Shypila Petr Shypila - 4 months ago 39
Javascript Question

Opening multiple websocket connections in single app

I need to perform a load testing on our websocket service.
Is there a way to open multiple websocket connections from a single workstation?

I already tried npm

modules to launch them with NodeJS. It works fine with a single connection, but when I try to open them in a for-loop it throws an exception or uses only last open client.


If you want to do it from a single workstation, you can use child processes :

app.js :

var cp = require('child_process');
var children = [];
var max = 10; // tweak this to whatever you want
for(var i = 0; i<max; i++){
    children[i] = cp.fork('./child.js');
    .on('error', function(e) {
    }).on('exit', function(code) {
      console.log('exit with code',code);

then in child.js, just have a script that starts a connection. you can also send messages between parent and child, using the child process API