Tag Archives: node.js

Proper settings for socket.io flash (and other) fallbacks for clients using a proxy

Salam (means hello) :)

I have the following basic settings in my node.js application. But it doesn't work for clients who are connected using a proxy or are behind a firewall. I want to know what should I add to get socket.io fallback to work as expected:

Server side:

var io = require('socket.io').listen(3000, {
    log: 3,
    flashPolicyServer: true,
    transports: ['htmlfile', 'xhr-polling', 'jsonp-polling', 'flashsocket']
});

io.sockets.on('connection', function(){
    // my event handlers
});

Client side:

WEB_SOCKET_SWF_LOCATION = "oath/to/my/copy/of/WebSocketMain.swf";
var socket = io.connect('http://localhost:3000');
// my event handlers

Proper settings for socket.io flash (and other) fallbacks for clients using a proxy

Salam (means hello) :)

I have the following basic settings in my node.js application. But it doesn't work for clients who are connected using a proxy or are behind a firewall. I want to know what should I add to get socket.io fallback to work as expected:

Server side:

var io = require('socket.io').listen(3000, {
    log: 3,
    flashPolicyServer: true,
    transports: ['htmlfile', 'xhr-polling', 'jsonp-polling', 'flashsocket']
});

io.sockets.on('connection', function(){
    // my event handlers
});

Client side:

WEB_SOCKET_SWF_LOCATION = "oath/to/my/copy/of/WebSocketMain.swf";
var socket = io.connect('http://localhost:3000');
// my event handlers

Node.js Unhandled ‘error’ event when using http.createServer().listen() on Ubuntu 12.04

Salam (means Hello) :)

I've developed a node.js script on my windows seven machine and it's working fine. but when I run it on my Ubuntu 12.04, the following error shows up and halts my app:

    throw er; // Unhandled 'error' event
              ^
Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Object.start (/httpServer/httpServer.js:9:34)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

and the point that caused error is .listen(80) in this line:

http.createServer(onRequest).listen(80); 
                             ^

I've also tried some other port numbers (like 100, 300, 500,...) instead of 80 and the error was still the same.

Node.js Unhandled ‘error’ event when using http.createServer().listen() on Ubuntu 12.04

Salam (means Hello) :)

I've developed a node.js script on my windows seven machine and it's working fine. but when I run it on my Ubuntu 12.04, the following error shows up and halts my app:

    throw er; // Unhandled 'error' event
              ^
Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Object.start (/httpServer/httpServer.js:9:34)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

and the point that caused error is .listen(80) in this line:

http.createServer(onRequest).listen(80); 
                             ^

I've also tried some other port numbers (like 100, 300, 500,...) instead of 80 and the error was still the same.

installing nodejs on ubuntu 12.10

Salam (means hello) :)

I'm trying to install node.js on my ubuntu 12.04 desktop. I've downloaded node package and followed readme file, ./configure and make commands worked fine, but make install command results in this:

nasser@nasser-pc:~/Downloads/node-v0.10.21$ sudo make install
[sudo] password for nasser: 
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory `/home/nasser/Downloads/node-v0.10.21/out'
  g++ '-DENABLE_DEBUGGER_SUPPORT' '-DENABLE_EXTRA_CHECKS' '-DV8_TARGET_ARCH_IA32' -I../deps/v8/src  -Wall -Wextra -Wno-unused-parameter -pthread -m32 -fno-strict-aliasing -O2 -fno-strict-aliasing -fno-tree-vrp -fno-rtti -fno-exceptions -MMD -MF /home/nasser/Downloads/node-v0.10.21/out/Release/.deps//home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o.d.raw  -c -o /home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o ../deps/v8/src/accessors.cc
make[1]: g++: Command not found
make[1]: *** [/home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o] Error 127
make[1]: Leaving directory `/home/nasser/Downloads/node-v0.10.21/out'
make: *** [node] Error 2

installing nodejs on ubuntu 12.10

Salam (means hello) :)

I'm trying to install node.js on my ubuntu 12.04 desktop. I've downloaded node package and followed readme file, ./configure and make commands worked fine, but make install command results in this:

nasser@nasser-pc:~/Downloads/node-v0.10.21$ sudo make install
[sudo] password for nasser: 
make -C out BUILDTYPE=Release V=1
make[1]: Entering directory `/home/nasser/Downloads/node-v0.10.21/out'
  g++ '-DENABLE_DEBUGGER_SUPPORT' '-DENABLE_EXTRA_CHECKS' '-DV8_TARGET_ARCH_IA32' -I../deps/v8/src  -Wall -Wextra -Wno-unused-parameter -pthread -m32 -fno-strict-aliasing -O2 -fno-strict-aliasing -fno-tree-vrp -fno-rtti -fno-exceptions -MMD -MF /home/nasser/Downloads/node-v0.10.21/out/Release/.deps//home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o.d.raw  -c -o /home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o ../deps/v8/src/accessors.cc
make[1]: g++: Command not found
make[1]: *** [/home/nasser/Downloads/node-v0.10.21/out/Release/obj.target/v8_base/deps/v8/src/accessors.o] Error 127
make[1]: Leaving directory `/home/nasser/Downloads/node-v0.10.21/out'
make: *** [node] Error 2

How to access cookie data inside a socket.io connection?

I am using node.js and socket.io. on the client side, I wrote a cookie like this:

var socket = io.connect('http://localhost:3000');
document.cookie="foo=bar";
socket.emit('this', { is: 'test'});

and on the server side, I need to be able to read from that cookie inside a socket.io connection, something like this:

io.sockets.on('connection', function (socket) {
    socket.on('this', function(reqData){ 
        console.log(socket.handshake.headers); // there is no cookies here!
    });
}

a no-framework solution is preferred, any help is appreciated. thanks.

update: in this gist you can find my complete code.