8

Note: I am using Mac OS 10.10 Yosemite

Important Note: None of the other questions and answers have worked for me.

I am following a tutorial which will have it so that I could have a multiplayer game. There is a file, which I have to download, which has a game.js file that I need to add this code into:


Note: I correctly downloaded socket.io in the correct directory.

var util = require("util"),
    io = require("socket.io").listen(80);

var socket,
    players;

function init() {
    players = [];
    socket = io.listen(8000);
    socket.configure(function() {
        socket.set("transports", ["websocket"]);
        socket.set("log level", 2);
    });
};

init();

But when I run node game.js, I get an error that looks like this:

Note: The Robhawks-mozzilla-festival-92336f2 folder is the folder that has all of the files in it



Why is the socket.configure messing up? Also, how can I fix it?

1

2 Answers 2

16

.configure() was removed when socket.io went to version 1.0. I'm guessing that the tutorial you're following is using an older version (0.9), but you have installed 1.0.

It would be best to move your code base to 1.0, as it's the latest. Configuration should be done as part of the server initialization:

var socket = require('socket.io')({
  transports  : [ 'websocket' ],
  ...
});

More info here.

However, since you're following a tutorial it may be easier to first get things up and running using the older version of socket.io, and once you have familiarized yourself with it, move to 1.0. In that case, install the older version:

$ npm install [email protected]
Sign up to request clarification or add additional context in comments.

2 Comments

The socket.io docs are very lacking. How do I set the port and the log level?
@NitzanWilnai logging/debugging is documented here, and setting the port depends on how exactly you're running socket.io (as part of an Express app, based on Node.js http, ...).
1

Looging socket.io v1.0 log-level option is removed. Thus for logging one has to start program using debug module.

  1. install debug: npm install debug -S
  2. then run the program: DEBUG=* node entry_file.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.