javascript - NodeJS How to implement request/response in net module -
javascript - NodeJS How to implement request/response in net module -
i new nodejs , working on project in using 'net' module. question can implement request, response model using 'net' module can accomplish in http module i.e. want when user type localhost:port number in browser can send response browser. can accomplish same using http , unable understand basic difference between 'net' , 'http' module:
my 'net' module code :
var net = require('net'); var server = net.createserver(function (con) { con.on('data', function (data) { <some code> }); con.on('end', function () { console.log('nodeserver disconnected'); }); }); server.listen(8888, function () { console.log('nodeserver listening port:8888'); });
following 'http' module code:
var http = require("http"); var fs = require("fs"); http.createserver(function(req, res){ res.writehead(200, { 'content-type': 'application/json', "access-control-allow-origin":"*" }); var obj = json.parse(fs.readfilesync('test', 'utf8')); res.write(json.stringify(obj, null, 4)); res.end(); }).listen(8888);
the reason want implement implement in net module getting xml url after fixed interval need convert json , homecoming json user when requested.
you can have @ post nodejs - net or http module
it states http built on top of net
i can't see on nodejs doc pages though
http://nodejs.org/api/net.html
http://nodejs.org/api/http.html
javascript json node.js http
Comments
Post a Comment