简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM