Pass additional data to socket.io server via io.connect

43 views
Skip to first unread message

ingo.f...@profitbricks.com

unread,
Feb 26, 2015, 5:22:05 AM2/26/15
to gevent-...@googlegroups.com
I want to pass additional data (the current page that is requested by the client) when connecting to my socket.io server, so that on the server I can send notifications specific for these pages.

Sample Javascript:
// like this
var socket = io.connect("/websocket", {'foo': 'bar'});
// or this
var socket = io.connect("/websocket?foo=bar");

My simplified server code:
class MyNamespace(BaseNamespace):

    def initialize(self):
        self.spawn(self.redis_tick)

    def redis_tick(self):
        r = get_redis()
        ps = r.pubsub()
        # Can I access the parameters from io.connect here?

NAMESPACES = {
    '/websocket': MyNamespace,
}

def socketio_serve(request):
    retval = None
    if 'socketio' in request.environ:
        # Can I access the parameters from io.connect here?
        retval = socketio_manage(request.environ, NAMESPACES, request)
    return HttpResponse(retval)

I inspected various parameters passed to my socket.io-serve function but I could not find out how to access the parameters passed with io.connect.
How can I access "foo" in by socket.io backend code?

Reply all
Reply to author
Forward
0 new messages