沈斌
2017-08-11 cd83ef88f783205bc17d06b249fa62f9425957c6
server.js
@@ -113,13 +113,8 @@
    }
}
mongoClient.connect(config.URL, function(err, db) {
    if (err) {
        console.log(err.message);
        return;
    }
    console.log('Connecting to Mongo DB at ' + config.URL);
function doTCPSocket(db) {
    //初始化三级警报通讯方式
    method.initConfigs(db);
@@ -141,8 +136,6 @@
                return;
            }
            //console.log(moment().format('YYYY-MM-DD HH:mm:ss') + " => " + value);
            doWork(db, socket, value);
        });
@@ -163,6 +156,25 @@
            console.log('Closed socket: ' + socket.remoteAddress +' '+ socket.remotePort);
        });
    }).listen(config.PORT, config.HOST);
    console.log('TCP Server listening on ' + config.HOST + ':' + config.PORT);
});
}
var db;
if(db == null) {
    mongoClient.connect(config.URL, function(err, database) {
        if (err) {
            console.log(err.message);
            return;
        }
        console.log('Connecting to Mongo DB at ' + config.URL);
        db = database;
        doTCPSocket(db);
    });
} else {
    console.log('==========*****==========');
    doTCPSocket(db);
}