1
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.on('sendchat', function (data) {
io.sockets.emit('updatechat', data);
});
});
這是我的websocket服務器(node.js + socket.io)。我瞭解除處理函數外的所有內容。有人可以解釋它做了什麼嗎? index.html做了什麼,它在哪裏?在我的客戶端,我使用一個名爲完全不同的剃鬚刀視圖,它無論如何都可以工作。socket.io服務器,處理函數
感謝
好的,謝謝你解釋 – Johan 2012-08-13 08:05:09