Skip to content

Instantly share code, notes, and snippets.

@korayal
Created December 7, 2012 12:34
Show Gist options
  • Save korayal/4232999 to your computer and use it in GitHub Desktop.
Save korayal/4232999 to your computer and use it in GitHub Desktop.
Node.js: UDP client (that should wait for a response before closing)
var dgram = require('dgram');
sendUDPMessage("10.1.2.3", 1234, Buffer("Release The Kraken!"));
function sendUDPMessage(targetIP, targetPORT, message){
var client = dgram.createSocket("udp4");
client.on('error', function(e) {
throw e;
});
client.on("message", function (msg, rinfo) {
console.log("got: \t" + msg + "\t from\t" + rinfo.address + ":" + rinfo.port);
client.close();
});
client.send(message, 0, message.length, targetPORT, targetIP, function(err, bytes) {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment