How can I get sessionId on server for indentify which connection

1,907 views
Skip to first unread message

nvc...@gmail.com

unread,
Aug 21, 2015, 3:31:22 PM8/21/15
to sockjs
My client code
sockjs = new SockJS(sockjs_url, null, {sessionId : 4 });

On sockjs-node
How can I read client generated sessionId ?
Some kind like this
sockjs_echo.on('connection', function(conn) {
    console
.log(conn.sessionId);


Bryce Kahle

unread,
Aug 21, 2015, 3:36:25 PM8/21/15
to nvc...@gmail.com, sockjs
Try conn._session.session_id


Bryce


--
You received this message because you are subscribed to the Google Groups "sockjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sockjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ken nvc

unread,
Aug 21, 2015, 9:22:07 PM8/21/15
to sockjs
I tried, but got "undefined"

Ken nvc

unread,
Aug 21, 2015, 9:34:29 PM8/21/15
to sockjs
My server code

var sockjs      = require('sockjs');
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"};
var sockjs_echo = sockjs.createServer(sockjs_opts);

// sockjs connect
sockjs_echo
.on('connection', function(conn) {
    console
.log(conn._session.session_id);



Do version /0.3.4 related to this error ?( sessionId undefined)


On Saturday, August 22, 2015 at 2:31:22 AM UTC+7, Ken nvc wrote:

Ken nvc

unread,
Aug 21, 2015, 9:38:01 PM8/21/15
to sockjs
My sockjs-node is 0.3.15

$ npm
--depth=-0 list
├── async@1.2.1
├── cron@1.0.9 extraneous
├── hiredis@0.4.0
├── node-static@0.7.6
├── redis@0.12.1
└── sockjs@0.3.15




On Saturday, August 22, 2015 at 2:31:22 AM UTC+7, Ken nvc wrote:

Bryce Kahle

unread,
Aug 21, 2015, 10:47:37 PM8/21/15
to nvc...@gmail.com, sockjs
It looks like websockets currently don’t populate the session_id property. All the other transports do though. If you are just looking for a unique session id, rather than use what is in the URL. You can use connection.id


Bryce


Ken nvc

unread,
Aug 21, 2015, 11:35:25 PM8/21/15
to sockjs
At web client side
How can I get connection_id after sockjs connected ?
And how can I get to know if sockjs is still connected so that I can feel safety when call sockjs.send(...)


On Saturday, August 22, 2015 at 2:31:22 AM UTC+7, Ken nvc wrote:

Bryce Kahle

unread,
Aug 21, 2015, 11:46:20 PM8/21/15
to nvc...@gmail.com, sockjs
Perhaps you should describe your use case for needing the connection ids?


Bryce


Ken nvc

unread,
Aug 22, 2015, 12:35:33 AM8/22/15
to sockjs
My case is:
Web client open websocket with Node server. (currently node server have connection_id)
When web client post data by http xhr request (data include connection_id)  to Django server, then Django server PUBLISH data to Redis.
Node receive SUBSCRIBE data , so Node know this data is sent by which connected client through connection_id in data.



On Saturday, August 22, 2015 at 2:31:22 AM UTC+7, Ken nvc wrote:

cuon...@dirox.net

unread,
Aug 25, 2015, 1:17:00 PM8/25/15
to sockjs, nvc...@gmail.com
Any suggestion please ?
Reply all
Reply to author
Forward
0 new messages