How to limit my node.js client connections to 2?

13,279

You can try with

server.maxConnections = 2;

Never used it but is looks like it's the way to go if I trust the Node.js documentation

Share:
13,279
Vlad Otrocol
Author by

Vlad Otrocol

I love my woman.

Updated on June 12, 2022

Comments

  • Vlad Otrocol
    Vlad Otrocol almost 2 years

    I am basically trying to only allow 2 clients to connect to the app concurrently. How should I approach this?

    This is my server code:

    var express = require('express'),
        app = express(),
        server = require('http').createServer(app),
        io = require('socket.io').listen(server);
    
    var osc = require('node-osc');
    
    var client = new osc.Client('127.0.0.1', 12345);
    
    server.listen(3000);
    
    app.get('/', function(req, res){
    
        res.sendfile(__dirname + '/index.html');
    });
    
    io.sockets.on('connection', function(socket){
        socket.on('send message', function(data){
            client.send('/oscAddress', parseInt(data));
        });
    });
    
  • Vlad Otrocol
    Vlad Otrocol over 10 years
    I tried this.. but for some reason the mouse position data i'm sending is now very slow.. or working every now and then, even though I only have 2 clients open
  • brnrd
    brnrd over 10 years
    If you send data each time your mouse moves, you are not one client, each sending is considered as a client by the server. That's why it's queuing the data. Why do you want to limit to 2 clients in the first place ?
  • Vlad Otrocol
    Vlad Otrocol over 10 years
    I'm trying to set up my phone as a controller for an arduino. The way it goes is: browser-server-open-frameworks(via osc)-arduino etc. I only need 2 controllers at the same time. Not more. I want to replace them when the other users disconnects.
  • Vlad Otrocol
    Vlad Otrocol over 10 years
    I accepted the answer as it fixed the problem I asked about.. However.. i did not ask the correct question. My problem persists.. data seems to be queueing and timing out and stuff
  • brnrd
    brnrd over 10 years
    You maybe should think of a solution based on a token, cookie or pool of connections to control that.
  • Vlad Otrocol
    Vlad Otrocol over 10 years
    Hmm.. This gets way to complicated for what I need.. I actually have a workaround. Instead of limiting the number of client connections(which was preferable) I can limit the number of osc channels. Thank you anyway for your help. :)
  • Flash Thunder
    Flash Thunder about 7 years
    And what if you're just using app.listen() ?