Socket.configure Undefined is not an error function


Note. I am using Mac OS 10.10 Yosemite

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

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


Note. I loaded socket.io correctly 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 message that looks like this:

Note. The Robhawks-mozzilla-festival-92336f2 folder is a folder in which there are all files.



Why did the .configure socket go bad? Also, how can I fix this?

+7
javascript websocket
source share
2 answers

.configure() was removed when socket.io switched to version 1.0. I assume that the tutorial you are using uses an older version (0.9), but you installed 1.0.

It’s best to move the code base to 1.0 as the last. Configuration should be performed as part of server initialization:

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

More details here .

However, since you are following the tutorial, it may be easier to get started and start using the old version of socket.io , and after you read it, go to 1.0. In this case, install the older version:

 $ npm install socket.io@0.9 
+14
source share
Parameter

Looging socket.io v1.0 log-level removed. Thus, for logging, you need to run the program using the debugging module.

  • install debug: npm install debug -S
  • then run the program: DEBUG=* node entry_file.js
+1
source share

All Articles