From cd83ef88f783205bc17d06b249fa62f9425957c6 Mon Sep 17 00:00:00 2001 From: 沈斌 <bluelazysb@hotmail.com> Date: Fri, 11 Aug 2017 09:54:33 +0800 Subject: [PATCH] 测试-不要频繁增加连接数 --- server.js | 33 ++++++++++++++++++++++----------- 1 files changed, 22 insertions(+), 11 deletions(-) diff --git a/server.js b/server.js index 921b518..3951072 100644 --- a/server.js +++ b/server.js @@ -41,7 +41,6 @@ if(value.startsWith('5a0000010003')) { var output = [ 0x6A, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6B ]; method.insertData(db, value, function(data, rank) { - //method.insertDocument2(db, value, rank, function(data) {}); var fields = method.padLeft(rank.toString(16), 8).match(/.{2}/g); output[6] = method.toDec(fields[0]); output[7] = method.toDec(fields[1]); @@ -114,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); @@ -142,8 +136,6 @@ return; } - //console.log(moment().format('YYYY-MM-DD HH:mm:ss') + " => " + value); - doWork(db, socket, value); }); @@ -164,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); -}); \ No newline at end of file +} + +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); +} -- Gitblit v1.8.0