0

I've been playing around with socket.io (very much a newbie), my goal is to post data to the server, do a small database entry and return data to the user real time.

My default server is nginx currently.

I've been looking at the example on socket.io, but this is only when wanting to use node.js to handle everything.

When trying to listen on port 3000, I get a warning of:

server:

  var io = require('socket.io').listen(3000);

  io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
  console.log(data);
  });
});

client:

<script src="/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect('http://localhost:3000');
    socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

I simply want to push the data from my web page to the node server, but whenever I do currently, I get a 404 for the socket.io/socket.io.js file. I've looked in to this, and other answers suggest having an update to date version of the node module express? I've ensured I have the latest versions of node.js, socket.io and express installed on my server.

Is there anywhere obvious where I'm going wrong here, sorry if this is an obvious question.

samayres1992
  • 779
  • 2
  • 12
  • 30

1 Answers1

1

Assuming you're running a Linux machine, there are two problems. For one, Nginx will already be running on port 80. Therefore, you can't run another process on that port, and should either run Node.js on another port, or follow a setup like this.

The other problem is that you need root access to use the ports < 1024 on a Linux machine. Without proper permission, you will get the EACCES error you're seeing.

Once the server binds properly, the socket.io.js file will no longer return a not found error.

Community
  • 1
  • 1
hexacyanide
  • 88,222
  • 31
  • 159
  • 162
  • Hi @hexacynide, I updated the code above in the post to my changes. Now the node runs on port 3000, and the client connects on 3000 also. But I still receive a 404 on the .js file, looking at my actual folders, there is no file in my public folder where I installed socket.io that is a socket.io.js file, is this expected? Thanks for the quick reply. – samayres1992 Dec 01 '13 at 02:24
  • It's also worth noting, the warning has gone now, thank you for that also, progress is great. – samayres1992 Dec 01 '13 at 02:28
  • 1
    You must change the script source in your HTML to accommodate the port. – hexacyanide Dec 01 '13 at 02:37