1

Is the node.js socket.io-client supposed to automatically handle cookies? That is, for all Set-Cookie response headers, is it supposed to pass back the corresponding Cookie headers during the handshake?

The reason I'm asking is because I have a proxy (the cloud foundry gorouter) between my client and 3 server instances. The socket.io server is appropriately setting two cookies (JSESSIONID and VCAP_ID) on the response and I need the client to send them back appropriately so that affinity is kept by the gorouter. I am currently getting connect failures due to a "transport error" when multiple instances of the server are running, but the problem goes away when I have a single server instance running.

Thanks in advance, Keith

Keith
  • 54
  • 1
  • 3

2 Answers2

0

If you want to access cookies in socket.io check out the following.

http://socket.io/docs/server-api/#namespace#use(fn:function):namespace

var io = require('socket.io')();
io.on('connection', function(socket){
  socket.to('others').emit('an event', { some: 'data' });
});

Additionally check out this post on how to do authentication in socket. Socket.IO Authentication

Community
  • 1
  • 1
Jeff Sloyer
  • 4,899
  • 1
  • 24
  • 48
0

Yes, I did get it to work, but the only node module I could get to work at the time was 'ws' as follows:

var WebSocket = require('ws');
var webSocketUrl = ""wss://" + ...
var opts = { headers: { Cookie: 'JSESSIONID=1; __VCAP_ID__='+vcapID} };
var socket = new WebSocket(websocketUrl,opts);

-- Keith

Keith
  • 54
  • 1
  • 3