简体   繁体   中英

Having problems running server.js file on Node.js with socket.io

I have been able to successfully run this a few months ago but I am suddenly having problems. It is for a whiteboard app that can also be seen here. The problem I am having is that when I run the command "node server.js" in the node.js command prompt I don't get anything, not even an error. I have tried other tests like Hello World and it has worked fine. My server.js file is listening on port:4000. I think this might be the issue. Here is the code if you think it might be something else.

(function() {
  var io;
  io = require('socket.io').listen(4000);
  io.sockets.on('connection', function(socket) {
    socket.on('drawClick', function(data) {
      socket.broadcast.emit('draw', {
        x: data.x,
        y: data.y,
        type: data.type
      });
    });
  });
}).call(this);

And to do better filtering, you can use the following :

DEBUG=* // all
DEBUG=socket.io:* // all in socket.io module
DEBUG=socket.io:server // only server debugger

It's not an issue. It's just a feature of Socket.IO 1.0, which was released a few weeks ago.

Form the official documentation :

Before 1.0, the Socket.IO server would default to logging everything out to the console. This turned out to be annoyingly verbose for many users (although extremely useful for others), so now we default to being completely silent by default.

and

The best way to see what information is available is to use the *:
DEBUG=* node yourfile.js

or in the browser:
localStorage.debug='*';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM