當前位置: 首頁>>代碼示例>>Python>>正文


Python FlashPolicyServer.stop方法代碼示例

本文整理匯總了Python中socketio.policyserver.FlashPolicyServer.stop方法的典型用法代碼示例。如果您正苦於以下問題:Python FlashPolicyServer.stop方法的具體用法?Python FlashPolicyServer.stop怎麽用?Python FlashPolicyServer.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socketio.policyserver.FlashPolicyServer的用法示例。


在下文中一共展示了FlashPolicyServer.stop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SocketIOServer

# 需要導入模塊: from socketio.policyserver import FlashPolicyServer [as 別名]
# 或者: from socketio.policyserver.FlashPolicyServer import stop [as 別名]

#.........這裏部分代碼省略.........
            ``heartbeat_timeout``.

        :param heartbeat_timeout: int The timeout for the client when
            it should send a new heartbeat to the server. This value
            is sent to the client after a successful handshake.

        :param close_timeout: int The timeout for the client, when it
            closes the connection it still X amounts of seconds to do
            re open of the connection. This value is sent to the
            client after a successful handshake.

        :param log_file: str The file in which you want the PyWSGI
            server to write its access log.  If not specified, it
            is sent to `stderr` (with gevent 0.13).

        """
        self.sockets = {}
        if 'namespace' in kwargs:
            print("DEPRECATION WARNING: use resource instead of namespace")
            self.resource = kwargs.pop('namespace', 'socket.io')
        else:
            self.resource = kwargs.pop('resource', 'socket.io')

        self.transports = kwargs.pop('transports', None)

        if kwargs.pop('policy_server', True):
            try:
                address = args[0][0]
            except TypeError:
                try:
                    address = args[0].address[0]
                except AttributeError:
                    address = args[0].cfg_addr[0]
            policylistener = kwargs.pop('policy_listener', (address, 10843))
            self.policy_server = FlashPolicyServer(policylistener)
        else:
            self.policy_server = None

        # Extract other config options
        self.config = {
            'heartbeat_timeout': 60,
            'close_timeout': 60,
            'heartbeat_interval': 25,
        }
        for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'):
            if f in kwargs:
                self.config[f] = int(kwargs.pop(f))

        if not 'handler_class' in kwargs:
            kwargs['handler_class'] = SocketIOHandler


        if not 'ws_handler_class' in kwargs:
            self.ws_handler_class = WebSocketHandler
        else:
            self.ws_handler_class = kwargs.pop('ws_handler_class')

        log_file = kwargs.pop('log_file', None)
        if log_file:
            kwargs['log'] = open(log_file, 'a')

        super(SocketIOServer, self).__init__(*args, **kwargs)

    def start_accepting(self):
        if self.policy_server is not None:
            try:
                if not self.policy_server.started:
                    self.policy_server.start()
            except error as ex:
                sys.stderr.write(
                    'FAILED to start flash policy server: %s\n' % (ex, ))
            except Exception:
                traceback.print_exc()
                sys.stderr.write('FAILED to start flash policy server.\n\n')
        super(SocketIOServer, self).start_accepting()

    def stop(self, timeout=None):
        if self.policy_server is not None:
            self.policy_server.stop()
        super(SocketIOServer, self).stop(timeout=timeout)

    def handle(self, socket, address):
        # Pass in the config about timeouts, heartbeats, also...
        handler = self.handler_class(self.config, socket, address, self)
        handler.handle()

    def get_socket(self, sessid=''):
        """Return an existing or new client Socket."""

        socket = self.sockets.get(sessid)

        if sessid and not socket:
            return None  # you ask for a session that doesn't exist!
        if socket is None:
            socket = Socket(self, self.config)
            self.sockets[socket.sessid] = socket
        else:
            socket.incr_hits()

        return socket
開發者ID:andrewosenenko,項目名稱:gevent-socketio,代碼行數:104,代碼來源:server.py


注:本文中的socketio.policyserver.FlashPolicyServer.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。