# Path: sockjs/cyclone/proto.py
# CONNECT = 'o'
# DISCONNECT = 'c'
# MESSAGE = 'm'
# HEARTBEAT = 'h'
# def disconnect(code, reason):
# 
# Path: sockjs/cyclone/transports/base.py
# class BaseTransportMixin(object):
# class MultiplexTransport(BaseTransportMixin):
#     def get_conn_info(self):
#     def session_closed(self):
#     def __init__(self, conn_info):
#     def get_conn_info(self):
# 
# Path: sockjs/cyclone/websocket.py
# class WebSocketHandler(cyclone.websocket.WebSocketHandler):
#     def _execute(self, *args, **kwargs):
#     def _closeIfInvalidMethod(self):
#     def _writeAndClose(self, resp):
#     def _closeIfInvalidUpgradeHeader(self):
#     def _closeIfInvalidConnectionHeader(self):


from twisted.python import log
from sockjs.cyclone import proto
from sockjs.cyclone.transports import base
from sockjs.cyclone import websocket
        # Stats
        self.server.stats.connectionOpened()

        # Disable nagle if required
        if self.server.settings['disable_nagle']:
           self.transport.setTcpNoDelay(True)

        # Handle session
        self.session = self.server.create_session(session_id, register=False)

        if not self.session.set_handler(self):
            self.transport.loseConnection()
            return

        self.session.verify_state()

        if self.session:
            self.session.flush()

    def _detach(self):
        if self.session is not None:
            self.session.remove_handler(self)
            self.session = None

    def messageReceived(self, message):
        # Ignore empty messages
        if not message or not self.session:
            return

        try:

# Path: sockjs/cyclone/proto.py
# CONNECT = 'o'
# DISCONNECT = 'c'
# MESSAGE = 'm'
# HEARTBEAT = 'h'
# def disconnect(code, reason):
# 
# Path: sockjs/cyclone/transports/base.py
# class BaseTransportMixin(object):
# class MultiplexTransport(BaseTransportMixin):
#     def get_conn_info(self):
#     def session_closed(self):
#     def __init__(self, conn_info):
#     def get_conn_info(self):
# 
# Path: sockjs/cyclone/websocket.py
# class WebSocketHandler(cyclone.websocket.WebSocketHandler):
#     def _execute(self, *args, **kwargs):
#     def _closeIfInvalidMethod(self):
#     def _writeAndClose(self, resp):
#     def _closeIfInvalidUpgradeHeader(self):
#     def _closeIfInvalidConnectionHeader(self):


# Path: sockjs/cyclone/transports/websocket.py
from twisted.python import log
from sockjs.cyclone import proto
from sockjs.cyclone.transports import base
from sockjs.cyclone import websocket

        # Stats
        self.server.stats.connectionOpened()

        # Disable nagle if required
        if self.server.settings['disable_nagle']:
           self.transport.setTcpNoDelay(True)

        # Handle session
        self.session = self.server.create_session(session_id, register=False)

        if not self.session.set_handler(self):
            self.transport.loseConnection()
            return

        self.session.verify_state()

        if self.session:
            self.session.flush()

    def _detach(self):
        if self.session is not None:
            self.session.remove_handler(self)
            self.session = None

    def messageReceived(self, message):
        # Ignore empty messages
        if not message or not self.session:
            return

        try:

            msg = proto.json_decode(message)