ブラウザがクライアントの socket.io.js を見つけられません:
<script src="/socket.io/socket.io.js"></script>
サーバーがハンドラーなしで作成された場合:
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs');
app.listen(80);
//without this part:
/*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.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
すべてPHPで生成するため、ハンドラー関数は必要ありません。また、index.html/php 以外のファイルに対してクライアント アプリケーション関数を使用する場合もあります。
では、ブラウザが socket.io.js を見つけられるようにするにはどうすればよいでしょうか?