Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
something is wrong when I send a UDP message
#I am running om Mac OS X 10.6.8
#I try with node 0.4.9
Version: v0.4.9
listening event fired
buffer created: my message is hallo world
#I try with node 0.4.9
Version: v0.4.8
listening event fired
buffer created: my message is hallo world
console.log('Version: ' + process.version);
var dgram = require('dgram'),
path = require("path");
var server = dgram.createSocket("unix_dgram"),
datagramPath = path.join(process.cwd(), "datagram_socket.udp");
server.on("message", function (message) {
console.log("message event fired");
console.log("UDP got: " + message);
});
server.on("listening", function () {
console.log("listening event fired");
var buffer = new Buffer("my message is hallo world");
console.log("buffer created: " + buffer.toString());
server.send(buffer, 0, buffer.length, datagramPath, function (err, bytes) {
console.log("send callback fired");
if (err) {
throw err;
}
console.log("Wrote " + bytes + " bytes to socket.");
});
});
server.bind(datagramPath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.