title: UDP Receiver trigger a function after some delay?
body: <p>I am coding some simple local machine search program. What i do is sending a UDP broadcast message and then wait for returning messages from the machines.</p>
  
  <p>Sender side:</p>
  
  <pre><code>setInterval(function sendUDP() { 
  
  var dgram = require('dgram');
  var client = dgram.createSocket("udp4");
  
  client.bind(function() { client.setBroadcast(false) });
  
  var message = new Buffer('getinfo');
  
  client.send(message, 0, message.length, 9080, "192.168.43.255", function(err, bytes) {
       client.close();
   });
  
  console.log("sended");
  
  return sendUDP; }(), 10000);
  </code></pre>
  
  <p>Sender side sends a UDP packet as a broadcast message, and the machines that receives those messages replies back via another port. I am listening these incoming messages on server side like:</p>
  
  <pre><code>var functions = require('./functiones.js');
  
  var PORT = 9081;
  var HOST = '0.0.0.0';
  
  
  var dgram = require('dgram');
  var server = dgram.createSocket('udp4');
  
  var IPAddresses=new Array();
  
  server.on('listening', function () {
     var address = server.address();      
      console.log('UDP Server listening on ' + address.address + ":" + 
  address.port);
  });
  
  server.on('message', function (message, remote) {
     IPAddresses.push(remote.address);
     console.log(String(message));
    console.log(functions.parseToName(message));
  });
  server.bind(PORT, HOST); 
  //updateJSON(IPAddresses);
  </code></pre>
  
  <p>So with above code i can take all messages.</p>
  
  <p>What i want to do is that creating a json file after taking all messages. Let's say i have 20 machines on the network and i need to trigger another function by passing <code>IPAddressess</code> array into it.  But machines just send messages, i may take 15 messages out of 20, the count is not important, if i do not have 5 machines on the network, then i will say their status is off. To create and Update a json file i need to trigger another function after receiver take messages from machines, but i cannot handle in which way i must trigger that function. There is no message coming by saying "yes my operation is done you can trigger that function to update JSON file".
  If i have a counter that always triggers that functions when time is out, i would probably have a conflict with sender side's timeout.</p>
  
  <p>Any advice and help would be great.</p>
  
  <p>Sincerely</p>