Node.js chat app doesn't load -
Node.js chat app doesn't load -
i created node.js chat app.. app doesn't load. code basic node.js chat app:
// load tcp library var net = require('net'); // maintain track of chat clients var clients = []; // start tcp server net.createserver(function (client) { console.log("connected!"); clients.push(client); client.on('data', function (data) { clients.foreach(function (client) { client.write(data); }); }); }).listen(5000); // set friendly message on terminal of server. console.log("chat server running\n"); after compile it, write in chrome browser localhost:5000 page maintain loading , never finish.
however, next code works perfectly:
// load tcp library net = require('net'); // start tcp server net.createserver(function (client) { client.write("hello world"); client.end(); }).listen(5000); run windows 7 64 bit on computer, , i'm using chrome. in advance!
you creating tcp/ip server using net module, accessing using http protocol using web browser.
this not match each other.
try connect server using telnet, e.g., , should fine.
alternatively, if want able connect using webbrowser, need utilize http module instead of net module.
node.js
Comments
Post a Comment