
var doWorkingData = function(io,jsondata){
	if( jsondata.cmd == "trap"){
		console.log("fucking.....data="+jsondata);
		io.sockets.emit('send:lutang', jsondata);
	}
	else if(jsondata.cmd == "alarm"){
			//alarm
	}
}


module.exports = function(io) {
	
	//create udp server
	var dgram = require("dgram");

	var server = dgram.createSocket("udp4");

	server.on("error", function (err) {
		console.log("server error:\n" + err.stack);
		server.close();
	});

	server.on("message", function (data, rinfo) {
		console.log("server got: " + data + " from " +
			rinfo.address + ":" + rinfo.port);

		var msg = data.toString();
		console.log('msg=' + msg);
		var jsondata = JSON.parse(msg);
		//for test

		//io.sockets.emit('send:alarm',jsondata);

					
		switch(rinfo.address){
			case "192.168.1.168":
				doWorkingData(io, jsondata);

				break;
			case "192.168.1.169":
				io.sockets.emit('send:lukou',JSON.parse(msg));
				break;
			case "192.168.1.170":
				io.sockets.emit('send:ranshi2ru',JSON.parse(msg));
				break;
			case "192.168.1.171":
				io.sockets.emit('send:ranshi2chu',JSON.parse(msg));
				break;
			case "192.168.1.172":
				io.sockets.emit('send:budairu',JSON.parse(msg));
				break;
			case "192.168.1.173":
				io.sockets.emit('send:budaichu',JSON.parse(msg));
				break;				
		}
		

	});

	server.on("listening", function () {
		var address = server.address();
		console.log("server listening " +
			address.address + ":" + address.port);
	});

	server.bind(12345);
	// server listening 0.0.0.0:41234

}
@@ -1,8 +1,655 @@
+%0Avar MongoClient = require('mongodb').MongoClient%0A    , format = require('util').format;%0A%0Avar doMongodbOpt = function(jsondata) %7B%0A%09MongoClient.connect('mongodb://127.0.0.1:27017/huanbao', function(err, db) %7B%0A    if(err) throw err;%0A%0A%0A    var collection = db.collection('alarms');%0A    collection.insert(jsondata, function(err, docs) %7B%0A%0A      collection.count(function(err, count) %7B%0A        console.log(format(%22count = %25s%22, count));%0A      %7D);%0A%0A      // Locate all the entries using find%0A      collection.find().toArray(function(err, results) %7B%0A        console.dir(results);%0A        // Let's close the db%0A        db.close();%0A      %7D);%0A    %7D);%0A  %7D)%0A%7D%0A%0A
 %0Avar doW
@@ -684,16 +684,16 @@
 ndata)%7B%0A
-
 %09if( jso
@@ -851,16 +851,105 @@
 %09//alarm
+ will save to redis and es%0A%09%09%09console.log(%22fuck.......mongo%22)%0A;%09%09%09doMongodbOpt(jsondata);
 %0A%09%7D%0A%7D%0A%0A%0A
@@ -1425,16 +1425,46 @@
 or test%0A
+%09%09doWorkingData(io, jsondata);
 %0A%09%09//io.

add mongodb support insert alarm collection