sockjs.tornado.session

sockjs.tornado.session

SockJS session implementation.

Base Session

class sockjs.tornado.session.BaseSession(conn, server)[source]

Base session implementation class

Constructor

BaseSession.__init__(conn, server)[source]

Base constructor.

conn
Connection class
server
SockJSRouter instance

Handlers

BaseSession.set_handler(handler)[source]

Set transport handler handler

Handler, should derive from the sockjs.tornado.transports.base.BaseTransportMixin.
BaseSession.verify_state()[source]

Verify if session was not yet opened. If it is, open it and call connections on_open

BaseSession.remove_handler(handler)[source]

Remove active handler from the session

handler
Handler to remove

Messaging

BaseSession.send_message(msg, stats=True, binary=False)[source]

Send or queue outgoing message

msg
Message to send
stats
If set to True, will update statistics after operation completes
BaseSession.send_jsonified(msg, stats=True)[source]

Send or queue outgoing message which was json-encoded before. Used by the broadcast method.

msg
JSON-encoded message to send
stats
If set to True, will update statistics after operation completes
BaseSession.broadcast(clients, msg)[source]

Optimized broadcast implementation. Depending on type of the session, will json-encode message once and will call either send_message or send_jsonifed.

clients
Clients iterable
msg
Message to send

State

BaseSession.close(code=3000, message='Go away!')[source]

Close session or endpoint connection.

code
Closing code
message
Close message
BaseSession.delayed_close()[source]

Delayed close - won’t close immediately, but on next ioloop tick.

BaseSession.is_closed[source]

Check if session was closed.

BaseSession.get_close_reason()[source]

Return last close reason tuple.

For example:

if self.session.is_closed:
code, reason = self.session.get_close_reason()

Connection Session

class sockjs.tornado.session.Session(conn, server, session_id, expiry=None)[source]

SockJS session implementation.

Constructor

Session.__init__(conn, server, session_id, expiry=None)[source]

Session constructor.

conn
Default connection class
server
SockJSRouter instance
session_id
Session id
expiry
Session expiry time

Session

Session.on_delete(forced)[source]

Session expiration callback

forced
If session item explicitly deleted, forced will be set to True. If item expired, will be set to False.

Handlers

Session.set_handler(handler, start_heartbeat=True)[source]

Set active handler for the session

handler
Associate active Tornado handler with the session
start_heartbeat
Should session start heartbeat immediately
Session.verify_state()[source]

Verify if session was not yet opened. If it is, open it and call connections on_open

Session.remove_handler(handler)[source]

Detach active handler from the session

handler
Handler to remove

Messaging

Session.send_message(msg, stats=True, binary=False)[source]

Send or queue outgoing message

msg
Message to send
stats
If set to True, will update statistics after operation completes
Session.send_jsonified(msg, stats=True)[source]

Send JSON-encoded message

msg
JSON encoded string to send
stats
If set to True, will update statistics after operation completes
Session.on_messages(msg_list)[source]

Handle incoming messages

msg_list
Message list to process

State

Session.flush()[source]

Flush message queue if there’s an active connection running

Session.close(code=3000, message='Go away!')[source]

Close session.

code
Closing code
message
Closing message

Heartbeats

Session.start_heartbeat()[source]

Reset hearbeat timer

Session.stop_heartbeat()[source]

Stop active heartbeat

Session.delay_heartbeat()[source]

Delay active heartbeat

Session._heartbeat()[source]

Heartbeat callback

Utilities

class sockjs.tornado.session.ConnectionInfo(ip, cookies, arguments, headers, path)[source]

Connection information object.

Will be passed to the on_open handler of your connection class.

Has few properties:

ip
Caller IP address
cookies
Collection of cookies
arguments
Collection of the query string arguments
headers
Collection of explicitly exposed headers from the request including: origin, referer, x-forward-for (and associated headers)
path
Request uri path

Project Versions

Table Of Contents

Previous topic

sockjs.tornado.router

Next topic

sockjs.tornado.migrate

This Page