Created
December 7, 2012 12:34
-
-
Save korayal/4232999 to your computer and use it in GitHub Desktop.
Node.js: UDP client (that should wait for a response before closing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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