我剛剛創建了一個node.js聊天應用..但該應用不加載。 代碼是非常基本的Node.js的聊天應用:Node.js聊天應用不加載
// Load the TCP Library
var net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a 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);
// Put a friendly message on the terminal of the server.
console.log("Chat server is running\n");
後,我編譯它,我寫在Chrome瀏覽器localhost:5000
但頁面是保持加載和寫不完。
但是,下面的代碼工作完美:
// Load the TCP Library
net = require('net');
// Start a TCP Server
net.createServer(function (client) {
client.write("Hello World");
client.end();
}).listen(5000);
我在我的電腦上運行Windows 7 64位,和我使用的鉻。
在此先感謝!
是否在控制檯中打印'「聊天服務正在運行」? – 2013-02-12 20:41:26