Can not run node.js from client

38 views
Skip to first unread message

thuan le minh

unread,
Aug 9, 2012, 3:39:33 AM8/9/12
to nod...@googlegroups.com
hi all ,
i wrote a simple demo program by node.js with bellow content on my linux server :

var http = require('http');
http.createServer(function(req, res){
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello word \n');
}).listen(1340, '127.0.0.1');

console.log("server running at http://127.0.0.1:1340");

when i test on my server with command : curl http://localhost:1340 . It ran normaly and result : "Hello word"

but , when i try test this program on my client machine . I use any webrowser ex : Mozila firefox, IE, google chrome (type : x.x.x.x:1340), it not work and return me an error message : Can not create connection to server x.x.x.x or connection timeout

 
so , what is error ? and how can i fix it ?

mscdex

unread,
Aug 9, 2012, 3:53:38 AM8/9/12
to nodejs
On Aug 9, 3:39 am, thuan le minh <leminhthua...@gmail.com> wrote:
> but , when i try test this program on my client machine . I use any
> webrowser ex : Mozila firefox, IE, google chrome (type : x.x.x.x:1340), it
> not work and return me an error message : *Can not create connection to
> server x.x.x.x or connection timeout

If you are using your browser on a machine other than localhost/
127.0.0.1 where the server is running, you need to change what
address(es) your server listens on. Currently your example server only
listens on localhost, if you want to listen on any address, either
don't specify an address (e.g. `listen(1340);`) or use '0.0.0.0'
instead.

greelgorke

unread,
Aug 9, 2012, 6:22:33 AM8/9/12
to nod...@googlegroups.com
127.0.0.1 or localhost is a loopback adapter address and only available from the same instance. listen to 0.0.0.0 or omit the ip.

Trang Nguyen

unread,
Aug 9, 2012, 3:47:47 AM8/9/12
to nod...@googlegroups.com

Make sure you ran it by http://<server_hostname>:1340.
If the issue still persists, check your firewall setting.





--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--

Best Regards,

 

NGUYEN TUNG TRANG

Email: tungt...@gmail.com

Cellphone: +84 903010290
Reply all
Reply to author
Forward
0 new messages