最近开始在学习 Node。 之前只用过 javascript 制作过一些简单的前端特效。 前不久了解到了 Node————表示对"TA"很有兴趣,于是就打算将自己的学习经历记录下来
//load model http
var http = require('http');
/*
*create the http server and listen 3001 port
*req is a client request
*res is a server reponsive
*/
http.createServer(function (req, res) {
//ressend message into the client
res.write('Hello,You hava started the service!');
//on req send the data emit the event
req.on('data', function (chunk) {
log('Reced Data!');
});
//on req end emit the event
req.on('end', function () {
res.end();
log('Req has closed!');
});
}).listen(3001);
log('Server Start');
log('Please open this-http://127.0.0.1:30001 in the Brower!');
function log(str){
console.log(str);
}
回复 (3)
C
用nodejs的http模块创建http服务器简直易如反掌,我觉得楼主可以尝试使用 net 模块,或者使用c++的socket能对http和网络协议有着更深的理解
Y
参与回复
登录后即可参与回复。登录