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?
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?
Share Improve this question edited Sep 6, 2015 at 18:08 asked Sep 6, 2015 at 18:00 user4930716user4930716 1- This tutorial on an online multi-player game is more up-to-date: blog.slashie.net/2015/09/25/… – Fedor Alexander Steeman Commented May 1, 2017 at 12:45
2 Answers
Reset to default 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]
Looging socket.io v1.0 log-level
option is removed. Thus for logging one has to start program using debug module.
- install debug:
npm install debug -S
- then run the program:
DEBUG=* node entry_file.js