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
Comments
-
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 over 10 yearsI 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 over 10 yearsIf 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 over 10 yearsI'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 over 10 yearsI 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 over 10 yearsYou maybe should think of a solution based on a token, cookie or pool of connections to control that.
-
Vlad Otrocol over 10 yearsHmm.. 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 about 7 yearsAnd what if you're just using app.listen() ?