GET http://localhost:8001/socket.io/1/?t=1441787711937 404 (Not Found)

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.

problem must be dir

try

http://localhost:8001/node_modules/socket.io/socket.io.js
http://localhost:8001/socket.io/socket.io.js

thanks for your response @pr0c3ss. I change the link to

<script src='http://localhost:8001/node_modules/socket.io/lib/socket.io.js'></script>

I have socket.io,js inside (lib) folder…I link to it and am getting error message

Uncaught Error: Module name "socket.io-client" has not been loaded yet for context: _. Use require([])

what else can I do?

have you installed node.js?
have you made a server.js script that node executes?

thanks for your time @pr0c3ss. I have installed node.js which I test for the version from cmd and the version is 2.11.3 using npm -v from my project directory folder…my server code is ServerPackage.js which I paste the code here and I got it started by running node serverPackage.js from cmd same directory. Please I know something is not right and this is really eating my time…I really want to get it work…please help me with any step by step that I need to follow base on the code I pasted here…How can I made a server.js script that the node will execute? …Thanks.

Sorry, but I’m not too clued up on this myself.

in console as root user
lsof -t 8001

see what services are running on port 8001 and kill…where x is the pid.
kill xxxx

rerun node with screen (temp development measure - wont be good in live production as it won’t restart node upon crash)
screen node ServerPackage.js

go to http://localhost:8001
what you see?

BIG THANK YOU @pr0css…it working now…thanks so much…hope to have you for future help :smile: …THANKS ONCE AGAIN :smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.