igm/sockjs-go

Getting session id from Conn object

Closed this issue · 4 comments

sockjs-go works fine.

but I think it needs a method to get session id.

cause some apps need to make channel to group connections.

in that case, that method required to group and share with other programs (like web) as a key for each connections.

igm commented

There's also a "raw websocket" type which does not have any session ID. I'm not sure how to handle that scenario. Any ideas how to solve this?

I used socket.io (https://github.com/LearnBoost/socket.io) often.

And I just read the code of socket.io and sockjs-client to answer. and found different thing.

socket.io server sends session id to client like this.


this.authorize(handshakeData, function (err, authorized, newData) {
if (err) return error(err);

if (authorized) {
  var id = self.generateId()
    , hs = [
          id
        , self.enabled('heartbeats') ? self.get('heartbeat timeout') || '' : ''
        , self.get('close timeout') || ''
        , self.transports(data).join(',')
      ].join(':');

  if (data.query.jsonp && jsonpolling_re.test(data.query.jsonp)) {
    hs = 'io.j[' + data.query.jsonp + '](' + JSON.stringify(hs) + ');';
    res.writeHead(200, { 'Content-Type': 'application/javascript' });
  } else {
    res.writeHead(200, headers);
  }

  res.end(hs);

  self.onHandshake(id, newData || handshakeData);
  self.store.publish('handshake', id, newData || handshakeData);

  self.log.info('handshake authorized', id);
} else {
  writeErr(403, 'handshake unauthorized');
  self.log.info('handshake unauthorized');
}

})


And, client receives session id and connect to server.

Following image shows receiving session id and possible connect-methods.

At last request, socket.io connect to session id included url.

image

But sockjs-client just generates random string for session id and connect to server.

I think best way is just send to client when it request 'info' page.

sockjs-go sending like this. {"websocket":true,"cookie_needed":false,"origins":[":"],"entropy":1298498081}

You can add a key 'sessionid'.

Whether sockjs-client use sessionid key or not, server and client can share session key.

of course I hope sockjs-client to use that key for session id if possible.

igm commented

I'm not sure I understand. What makes it confusing for me is the "info" in connection to "session id".
Info requests are not bound to any session, the url for "echo" info looks like:

http://<server>:<port>/echo/info

Whereas the URL for xhr_streamings looks like:

http://<server>:<port>/echo/<serverid><sessionid>/xhr_streaming

The second thing is that this is server side only, I have no intentions to modify in any way the socksj-cient library.

igm commented

Done (in master, not v1)
242b05a