沈斌
2016-12-15 b5b999614dad2d58d85a663b4c29e0265a790c6b
server.js
@@ -7,6 +7,7 @@
var mongoClient = require('mongodb').MongoClient;
var config = require('./config');
var method = require('./method');
var queue = require('./queue');
var map = {
    "5a0000010001": 32,
@@ -37,7 +38,7 @@
    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) {});
            //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]);
@@ -101,6 +102,9 @@
    if(length > 0) {
        var value = data.slice(0, length);
        console.log(moment().format('YYYY-MM-DD HH:mm:ss') + " => " + value);
        queue.publishMessage(value);
        handleData(db, socket, value);
        doWork(db, socket, data.slice(length));
@@ -108,7 +112,10 @@
}
mongoClient.connect(config.URL, function(err, db) {
    if (err) return;
    if (err) {
        console.log(err.message);
        return;
    }
    console.log('Connecting to Mongo DB at ' + config.URL);
    net.createServer().on('connection', function(socket){
@@ -132,7 +139,7 @@
        });
        socket.on('end', function(){
            console.log(count)
        });
        socket.on('error', function(error) {
@@ -146,10 +153,6 @@
        socket.on('close', function(data) {
            console.log('Closed socket: ' + socket.remoteAddress +' '+ socket.remotePort);
        });
        socket.on('close', function(data) {
            console.log('Closed socket: ' + socket.remoteAddress + ' ' + socket.remotePort);
        });
    }).listen(config.PORT, config.HOST);