5

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));
    });
});

1 Answer 1

11

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

Sign up to request clarification or add additional context in comments.

7 Comments

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
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 ?
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.
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
You maybe should think of a solution based on a token, cookie or pool of connections to control that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.