Skip to content

Instantly share code, notes, and snippets.

@makotom
Created April 28, 2014 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makotom/11366441 to your computer and use it in GitHub Desktop.
Save makotom/11366441 to your computer and use it in GitHub Desktop.
Basic script to handle JSON from ntp.nict.jp
(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