码迷,mamicode.com
首页 > Web开发 > 详细

NodeJs Http 外网访问

时间:2015-03-11 12:21:41      阅读:743      评论:0      收藏:0      [点我收藏+]

标签:

NodeJs 官方代码:

example.js http

var http = require(‘http‘);
http.createServer(function (req, res) {
        res.writeHead(200, {‘Content-Type‘: ‘text/plain‘});
        res.end(‘Hello World\n‘);
}).listen(9337, ‘127.0.0.1‘);
console.log(‘Server running at http://127.0.0.1:9337/‘);

example.js tcp

var net = require(‘net‘);
var server = net.createServer(function (socket) {
        socket.write(‘Echo server\r\n‘);
        socket.pipe(socket);
});
server.listen(9337, ‘127.0.0.1‘);

运行 

node example.js

访问

http://127.0.0.1:9337/

如果部署在服务器,需要外网访问,把127.0.0.1改为对应服务器的IP地址,对应的防火墙端口开放出来 就好了




NodeJs Http 外网访问

标签:

原文地址:http://www.cnblogs.com/myfield/p/4329495.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!