Created
October 8, 2010 18:56
-
-
Save rjungemann/617324 to your computer and use it in GitHub Desktop.
UDP client and server in Node
This file contains hidden or 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 client = dgram.createSocket("udp4"); | |
client.on("message", function(data, info) { | |
console.log("got: " + data.toString("utf8") + " from " + info.address); | |
}); | |
client.on("listening", function() { | |
console.log("client listening " + client.address().address); | |
setTimeout(function() { | |
var message = new Buffer("A message at " + (new Date())); | |
client.send(message, 0, message.length, 8001, "localhost"); | |
}, 5000); | |
}); | |
client.bind(8002, "localhost"); |
This file contains hidden or 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 server = dgram.createSocket("udp4"); | |
server.on('message', function(data, info) { | |
console.log(data.toString("utf8"), info); | |
}); | |
server.bind(8001, "localhost"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment