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 ビットを実行しており、Chrome を使用しています。
前もって感謝します!