Created
April 28, 2014 09:17
-
-
Save makotom/11366441 to your computer and use it in GitHub Desktop.
Basic script to handle JSON from ntp.nict.jp
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
(function(){ | |
var SERVERS = [ | |
"http://ntp-a1.nict.go.jp/cgi-bin/jsont", | |
"http://ntp-b1.nict.go.jp/cgi-bin/jsont" | |
], | |
http = require("http"); | |
(function(){ | |
var jsont = function(body){ | |
return body; | |
}, | |
postrun = function(res){ | |
var fullStr = ""; | |
res.on("data", function(chunk){ | |
fullStr += chunk.toString(); | |
}); | |
res.on("end", function(){ | |
var serverInfo = eval(fullStr); | |
console.log(serverInfo); | |
}); | |
}, | |
fireServerReq = function(serverName, postrun){ | |
http.get(encodeURI(serverName + "?" + (new Date().getTime() / 1000).toString()), postrun); | |
}; | |
SERVERS.forEach(function(server){ | |
fireServerReq(server, postrun); | |
}); | |
})(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment