私はsocket.ioにまったく慣れていないので、ホームページの例から始めて足を踏み入れようとしています。しかし、実行後にコンソールに表示されるのはこれだけです
debug - 提供される静的コンテンツ /socket.io.js
私のサーバー側のコードは次のとおりです。
var app=require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(80);
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) {
console.log("connected");
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
})
そして私のindex.htmlは次のようになります:
var socket = io.connect('document.location.href');
socket.on('error',function(reason){
// console.error("Error");
});
socket.on('connect', function () {
console.log('connected');
socket.send('hi');
socket.on('message', function (msg) {
// my msg
});
});
</script>
私はそれについてグーグルで調べましたが、問題を解決できませんでした。私はfirefoxでubuntuを使用しています。