Socket.io: Getting HTTP Header 400 while using polling on socket.io

Created on 22 Apr 2015  ·  4Comments  ·  Source: socketio/socket.io

Hi,

I am getting lots of 400 HTTP Headers while using polling on socket.io.
I am using nodejs cluster:
Here is the code snippet:

if (cluster.isMaster) {
// Fork workers.
//numCPUs=1;
for (var i = 0; i < numCPUs-1; i++) {
cluster.fork();
}
}
//worker code:
else{

var socket_io = require('socket.io')(server);
var redis_adapter = require('socket.io-redis');
socket_io.adapter(redis_adapter({ host: config.redis.ip, port: config.redis.port }));

//rest of the code
socket_io.on('connection', function (socket) {

}

Any pointer in this regard will be helpful.

Thanks in Advance

Closed due to inactivity

Most helpful comment

Hi! I had a lot of trouble setting up a cluster with socket.io, as there are not a lot of examples. I have a working example i use to control some raspberryPi's at

https://github.com/jordanpappas/raspi-car/tree/master/server

I really need to make a separate example in order to show how to get this working, but for now you can check out the index file in the link. There are a few things you have to be sure to do in order to get this to work.

  1. Use redis (you already seem to be doing that, so compare how you wired up the adapter to my example)
  2. Use websockets only. This is true for both clients and the server. These errors you are getting have to do with the polling stuff, so don't use it. Do this like this
var io = sio(server, { 'transports': ['websocket'] });

and on client:

var socket = io.connect('http://localhost:3000', { 'transports': ['websocket'] });

This should get you moving in the right direction, and i'll work on getting a simple example together.

All 4 comments

Hi! I had a lot of trouble setting up a cluster with socket.io, as there are not a lot of examples. I have a working example i use to control some raspberryPi's at

https://github.com/jordanpappas/raspi-car/tree/master/server

I really need to make a separate example in order to show how to get this working, but for now you can check out the index file in the link. There are a few things you have to be sure to do in order to get this to work.

  1. Use redis (you already seem to be doing that, so compare how you wired up the adapter to my example)
  2. Use websockets only. This is true for both clients and the server. These errors you are getting have to do with the polling stuff, so don't use it. Do this like this
var io = sio(server, { 'transports': ['websocket'] });

and on client:

var socket = io.connect('http://localhost:3000', { 'transports': ['websocket'] });

This should get you moving in the right direction, and i'll work on getting a simple example together.

Sure thanks.I solved the issue.I was using sticky session library inside cluster worker which is wrong as the library itself creates the workers.

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

Waste 4 hours in this problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karmac2015 picture karmac2015  ·  3Comments

adammw picture adammw  ·  4Comments

Elliot9 picture Elliot9  ·  4Comments

stnwk picture stnwk  ·  4Comments

MyMomSaysIAmSpecial picture MyMomSaysIAmSpecial  ·  4Comments