2
這可能聽起來很奇怪,但我試圖讓很簡單的網絡聊天,我需要幫助..
的Node.js - 卡在製作簡單的網絡聊天
我做了這麼遠與節點 -
var http = require('http');
var fs = require('fs');
var path = require('path');
var messages = [];
// Simple Function to load HTML/JavaScript/CSS Files
function LoadHTML(html, requrl, res) {
var filePath = '.' + requrl;
if (filePath == './') {
filePath = './' + html;
}
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
}
fs.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}
});
}
else {
res.writeHead(404);
res.end();
}
});
}
http.createServer(function (req, res) {
LoadHTML('index.html', req.url, res);
}).listen(8125);
的HTML/CSS我使用 - http://jsfiddle.net/yZ5at/
從這裏我堅持..我想是當T他用戶在textarea中鍵入內容,然後按回車鍵,他的文本將顯示在聊天分區中。
但我該怎麼做?請幫忙嗎?