如何将我的 node.js 客户端连接限制为 2 个? [英] How to limit my node.js client connections to 2?

查看:21
本文介绍了如何将我的 node.js 客户端连接限制为 2 个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上试图只允许 2 个客户端同时连接到应用程序.我应该如何处理这个问题?

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

这是我的服务器代码:

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

推荐答案

你可以试试

server.maxConnections = 2;

从未使用过它,但如果我相信 Node.js 文档

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

这篇关于如何将我的 node.js 客户端连接限制为 2 个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆