mohammed elfatih
mohammed elfatih

Reputation: 11

how to open multiple connections with socket.connect()

I need to open a number of connections with a number of devices at the same moment using Node.js.

Each client has a digital scale client, his scale IP is connected for the first user, but the second user is failing and got this error:

Error: connect EISCONN 192.168.2.1:3002 - Local (192.168.2.100:62771)

var handleRegister =function (ip,userid)
{
 scaleconnect.connect(3002, ip, function() {

 scaleconnect.on('data', function(data) {


            io.to(userid).emit('weighScale', data.toString('utf8'));

            });

          });
          scaleconnect.on('error', function(ex) {
           console.log(ex);
         }); 
}

Upvotes: 1

Views: 834

Answers (1)

Dan D.
Dan D.

Reputation: 74655

You need to create a new connection object for each simultaneous connection.

The error is from reusing the one named by scaleconnect while it has an established connection.

Upvotes: 1

Related Questions