/**
 * Created by tungtouch on 2/5/15.
 */

/*
* Listen UDP from Device: 128.199.126.250
* */

var dgram = require("dgram");
var colors = require('colors');
var Dequeue = require('dequeue')
var async = require('async');
var redis = require("redis");
var rClient = redis.createClient();
var FIFO = new Dequeue();
//var ports = [4000, 4001, 4002, 3333, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011];
var ports = [4444];
var r = 0;

var client = dgram.createSocket('udp4');


rClient.on("error", function (err) {
    console.log("Error " + err);
});


fetcher();

function fetcher() {
    console.log("Fetcher Rung", FIFO);
    while (FIFO.length > 0)
    {
        var msg = FIFO.shift();
        console.log("Message: ", msg);
        //process.nextTick(fetcher);
    }
    //setImmediate(fetcher); //make this function continuously run
}

for(var i=0; i < ports.length; i++){

    console.log("Start listen port ",i,":", ports[i]);

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


    client.on("message", function (msg, rinfo) {
        console.log("Message:", msg);
        FIFO.push(msg);

    });

    client.bind(ports[i]);
}

@@ -613,297 +613,8 @@
 );%0A%0A
-%0Afetcher();%0A%0Afunction fetcher() %7B%0A    console.log(%22Fetcher Rung%22, FIFO);%0A    while (FIFO.length %3E 0)%0A    %7B%0A        var msg = FIFO.shift();%0A        console.log(%22Message: %22, msg);%0A        //process.nextTick(fetcher);%0A    %7D%0A    //setImmediate(fetcher); //make this function continuously run%0A%7D
 %0A%0Afo
@@ -647,16 +647,31 @@
 h; i++)%7B
+%0A    fetcher();
 %0A%0A    co
@@ -967,24 +967,24 @@
 ;%0A%0A    %7D);%0A%0A
-
     client.b
@@ -997,11 +997,329 @@
 rts%5Bi%5D);
+%0A%0A    function fetcher() %7B%0A        console.log(%22Fetcher Rung%22, FIFO);%0A        while (FIFO.length %3E 0)%0A        %7B%0A            var msg = FIFO.shift();%0A            console.log(%22Message: %22, msg);%0A            //process.nextTick(fetcher);%0A        %7D%0A        //setImmediate(fetcher); //make this function continuously run%0A    %7D
 %0A%7D%0A

Update UDPefef