I am trying to set the configuration for socket.io as per https://github.com/LearnBoost/socket.io/wiki/Configuring-Socket.IO
io.set('log level', 1);
But I'm getting TypeError: Object # has no method 'set' ... what's wrong? I have io = require("socket.io")
Also tried,
io.configure('production', function(){
io.set('log level', 1);
});
but no luck. what's wrong ?
EDIT:
require.paths.push('/cygdrive/c/Personal/software/nodejs/NODE/node_modules');
var express = require("express"),
fs = require("fs"),
form = require('connect-form'),
app = express.createServer(
form({ keepExtensions: true })
),
sys = require("sys"),
RentModel = require("./rent_schema"),
UserModel = require("./track_schema"),
io = require("socket.io"),
fb = require('facebook-js'),
Twitter = require('./Twitter_Analysis'),
Foursquare = require('./Foursquare_Analysis'),
YQL = require("yql"),
settings = require("./settings");
socket = io.listen(app);
:::::::::::::::::
app.listen(9999);
This works fine.. But if I change it to io = require("socket.io").listen(8080) it gives me error, listen method not found.
The bidirectional channel between the Socket.IO server (Node. js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.
socket.io rooms are a lightweight data structure. They are simply an array of connections that are associated with that room. You can have as many as you want (within normal memory usage limits). There is no heavyweight thing that makes a room expensive in terms of resources.
Even when websockets can be used, the initial connection setup it done over HTTP. Also, a socket.io server will attach to an HTTP server so it can serve its own client code through /socket.io/socket.io.js .
require('socket.io')
returns a Socket object. The set properties are on socket.io-manager. The manager is returned by require('socket.io').listen(server)
call.
Note that you should be passing a web server to socket.io, not just a port:
var app = require('http').createServer(handler),
io = require('socket.io').listen(app);
io.set('log level', 2);
app.listen(8080); // this is the server, not socket.io
You want var io = require('socket.io').listen(80);
instead of just require.
var io = require('socket.io').listen(80);
io.configure( function(){
io.set('log level', 3);
});
There is one important thing to note here. If you get the error*process.nextTick error, or 'error' event on first tick...* that means that you have another webserver, like Apache, listening to port 80.
So, if you chnage the port to, for example 8080, it should work:
var io = require('socket.io').listen(8080);
io.configure( function(){
io.set('log level', 3);
});
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With