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中键入内容,然后按回车键,他的文本将显示在聊天分区中。
但我该怎么做?请帮忙吗?