我无法增加MaxSockets值

时间:2013-08-13 14:54:00

标签: javascript node.js sockets socket.io

我正在使用带有xhr-polling的socket.io但是xhr有5个连接限制。我无法增加它。我更改了maxSockets变量但我仍有5个连接限制。

如何解决此问题?我尝试了一切,但无法解决它。

var db_helper = require("./dhelper.js");
var io=require('socket.io');
var http=require('http');
http.globalAgent.maxSockets = 20;
http.Agent.maxSockets = 20;
var server = http.createServer().listen(
    2772);
var options = {
    transports: [
         'xhr-polling'
    ],
    'force new connection': true
};
io = io.listen(server,options);

var check = require('validator').check,
    sanitize = require('validator').sanitize;
var roomid=0;
var anonid;
var ilet;
var userip;
var blck_id;


io.sockets.on('connection',function(socket){
       socket.on('mesajgonder',function(data) {
       data.mesaj = sanitize(data.mesaj).escape();
            if (data.alan == "" ) { return false; }
           if (data.gonderen == "anon") {
           userip=socket.handshake.address.address;
            userip=userip.replace(".","");
            userip=userip.replace(".","");
            userip=userip.replace(".","");
            anonid=userip+'-'+data.alan+'-'+socket.id;
            blck_id=userip+'-'+data.alan;
            socket.join(anonid);
            socket.join('close_status'+data.alan);
               ilet={
                mesaj:data.mesaj,
                gonderen:anonid,
                alici:data.alan,
                blck_id:blck_id
                }
           }else{
               ilet={
                   mesaj:data.mesaj,
                   gonderen:data.gonderen,
                   alici:data.alan
               }
           }
           if (data.gonderen == "anon") {
                io.sockets.in(data.alan).emit('listele',ilet);
                io.sockets.in(anonid).emit('listele',ilet);
           }else{
               io.sockets.in(data.gonderen).emit('listele',ilet);
               io.sockets.in(data.alan).emit('listele',ilet);
           }
        });
        socket.on("hostkayit",function(data) {
            socket.join(data);
            var send={
                username:data,
                session:socket.id,
                durum:"ekle"
            }
            db_helper.onlineusers(send,function(data) {

            });

        });
        socket.on("writing",function(data) {
            if (data.to == "") { return false; }
            io.sockets.in(data.to).emit('writing_status',data.sender);

        });
        socket.on('close',function(data) {
            if (data.from != "anon") {

                var send={
                    username:data.from,
                    session:socket.id,
                    durum:"sil"
                }
                if (data.c_session == "yes") {
                    db_helper.onlineusers(send,function(data) {

                    });
                }
                if (data.to == "") {
                    io.sockets.in('close_status'+data.from).emit('closed',data.from);

                }else{
                    io.sockets.in(data.to).emit('closed',data.from);

                }
            }else{
                userip=socket.handshake.address.address;
                userip=userip.replace(".","");
                userip=userip.replace(".","");
                userip=userip.replace(".","");
                data.from=userip+'-'+data.to+'-'+socket.id;
                io.sockets.in(data.to).emit('closed',data.from);

            }


        });

0 个答案:

没有答案