socket.io is not working…am getting the error message http://localhost:8001/socket.io/1/?t=1441787711937 404 (Not Found) from the browser console.
Here is the server code (serverPackage.js).
var static = require('node-static');
var http = require('http');
var file = new(static.Server)();
var app = http.createServer(function(req, res) {
file.serve(req, res);
}).listen(8001);
var io = require('socket.io').listen(app);
io.sockets.on('connection', function(socket) {
socket.on('message', function(message) {
log('S --> got message: ', message);
socket.broadcast.to(message.channel).emit('message', message);
});
socket.on('create or join', function(room) {
var numClients = io.sockets.clients(room).length;
log('S --> Room ' + room + ' has ' + numClients + ' client(s)');
log('S --> Request to create or join room', room);
if (numClients == 0) {
socket.join(room);
socket.emit('created', room);
} else if (numClients == 1) {
io.sockets.in(room).emit('join', room);
socket.join(room);
socket.emit('joined', room);
} else {
socket.emit('full', room);
}
});
function log() {
var array = [">>> "];
for (var i = 0; i < arguments.length; i++) {
array.push(arguments[i]);
}
socket.emit('log', array);
}
});
and this is how the socket.io is link to the browser: (index.html)
<script src='http://localhost:8001/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js'></script>
the package.json is
{
"name": "video_call",
"version": "1.0.0",
"description": "A simple video call app",
"main": "serverPackage",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "AOS",
"license": "ISC",
"dependencies":{
"express":"3.x",
"socket.io":"0.9.x"
}
}
I have the index.html, the serverPackage.js, the package.json and the (node_modules folder) in the same folder directory.
I do not know what is wrong and why it cant find it. can anyone please help me out.