我正在学习node.js,并试图连接到我创建的服务器,但我的浏览器无法连接。我正在一台实时服务器上进行测试。简单的node.js,连接到服务器
我在我的/的public_html server.js由这样的:
var http = require("http");
function onRequest(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started");
我通过节点server.js从控制台启动和我得到的“服务器已启动”的消息,但是当我指出我的浏览器在myhost.com:8888它不会连接,尝试了很长时间后,我得到错误101(net :: ERR_CONNECTION_RESET):连接被重置。我忘了什么?
想知道 - 是否为您在本地主机上工作?你确定网址是否正确 - 你是否尝试过使用IP地址和端口号进行连接,而不是使用URL? – 2012-07-18 01:13:02