Created
November 29, 2011 20:17
-
-
Save erickr/1406283 to your computer and use it in GitHub Desktop.
Logging udp-messages to a file with node.js
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 dgram = require("dgram"); | |
var fs = require('fs'); | |
var server = dgram.createSocket("udp4"); | |
var messageToSend = new Buffer("A message to send"); | |
server.on("message", function (msg, rinfo) { | |
var stream = fs.createWriteStream("udp-stream.log", {'flags': 'a'}); | |
stream.once('open', function(fd) { | |
stream.write("From "+rinfo.address+":"+rinfo.port+"\n"+msg+"\n"); | |
}); | |
}); | |
server.on("listening", function () { | |
var address = server.address(); | |
console.log("server listening " + | |
address.address + ":" + address.port); | |
}); | |
server.bind(4711); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment