예제 #1
0
    def open(self, session_id):
        """WebSocket open handler"""

        for _ in range(3):
            self.session = self.server.get_session(session_id)
            if self.session is None:
                self.session = self.server.create_session(self.request)

            if self.session is not None:
                break
                

        if not self._is_active:
            # Need to check if websocket connection was really established by sending hearbeat packet
            # and waiting for response
            self.write_message(proto.heartbeat())
            self.server.io_loop.add_timeout(time.time() + self.server.settings['client_timeout'],
                                            self._connection_check)
        else:
            # Associate session handler
            self.session.set_handler(self)
            self.session.reset_heartbeat()

            # Flush messages, if any
            self.session.flush()
예제 #2
0
    def _heartbeat(self):
        """Heartbeat callback"""
        self.send_message(proto.heartbeat())

        self._missed_heartbeats += 1

        # TODO: Configurable
        if self._missed_heartbeats > 2:
            self.close()
예제 #3
0
    def _heartbeat(self):
        """Heartbeat callback"""
        self.send_message(proto.heartbeat())

        self._missed_heartbeats += 1

        # TODO: Configurable
        if self._missed_heartbeats > 2:
            self.close()
예제 #4
0
    def open(self, session_id):
        """WebSocket open handler"""
        self.session = self.server.get_session(session_id)
        if self.session is None:
            raise HTTPError(401, "Invalid Session")

        if not self._is_active:
            # Need to check if websocket connection was really established by sending hearbeat packet
            # and waiting for response
            self.write_message(proto.heartbeat())
            self.server.io_loop.add_timeout(time.time() + 5, self._connection_check)
        else:
            # Associate session handler
            self.session.set_handler(self)
            self.session.reset_heartbeat()

            # Flush messages, if any
            self.session.flush()
예제 #5
0
    def open(self, session_id):
        """WebSocket open handler"""
        self.session = self.server.get_session(session_id)
        if self.session is None:
            raise tornado.HTTPError(401, "Invalid Session")

        if not self._is_active:
            # Need to check if websocket connection was really established by sending hearbeat packet
            # and waiting for response
            self.write_message(proto.heartbeat())
            self.server.io_loop.add_timeout(time.time() + 5, self._connection_check)
        else:
            # Associate session handler
            self.session.set_handler(self)
            self.session.reset_heartbeat()

            # Flush messages, if any
            self.session.flush()