当前位置: 首页>>代码示例>>Python>>正文


Python SocketIOServer.kill方法代码示例

本文整理汇总了Python中socketio.server.SocketIOServer.kill方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIOServer.kill方法的具体用法?Python SocketIOServer.kill怎么用?Python SocketIOServer.kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socketio.server.SocketIOServer的用法示例。


在下文中一共展示了SocketIOServer.kill方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import kill [as 别名]
    def handle(self, addrport="", *args, **options):

        if not addrport:
            self.addr = HOST
            self.port = PORT
        else:
            m = match(naiveip_re, addrport)
            if m is None:
                raise CommandError('"%s" is not a valid port number '
                                   'or address:port pair.' % addrport)
            self.addr, _, _, _, self.port = m.groups()

        # Make the port available here for the path:
        #   socketio_tags.socketio ->
        #   socketio_scripts.html ->
        #   io.Socket JS constructor
        # allowing the port to be set as the client-side default there.
        environ["DJANGO_SOCKETIO_PORT"] = str(self.port)

        start_new_thread(reload_watcher, ())
        try:
            bind = (self.addr, int(self.port))
            print
            print "SocketIOServer running on %s:%s" % bind
            print
            handler = self.get_handler(*args, **options)
            server = SocketIOServer(bind, handler, resource="socket.io")
            server.serve_forever()
        except KeyboardInterrupt:
            if RELOAD:
                server.kill()
                print
                print "Reloading..."
                restart_with_reloader()
            else:
                raise
开发者ID:IsaacRay,项目名称:django-socketio,代码行数:38,代码来源:runserver_socketio.py

示例2: handle

# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import kill [as 别名]
 def handle(self, *args, **kwargs):
     """Run the websocket server."""
     
     # Set the settings module for the websocket server.
     if 'DJANGO_SETTINGS_MODULE' not in os.environ:
         os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
     
     # Import the WSGI handler.
     application = self.get_handler(*args, **kwargs)
     
     # Print nice things to the console; make it look mostly like
     # the traditional Django dev server.
     print "Django version {version}, using settings '{settings}'.".format(
         settings=os.environ['DJANGO_SETTINGS_MODULE'],
         version=django.get_version(),
     )
     print ' '.join((
         'SocketIO server is listening on port %d' % kwargs['port'],
         'and on port 843 (Flash policy server).',
     ))
     print 'Quit the server with CONTROL-C.'
     
     # Create the SocketIO server.
     # Pay special attention here to the `resource` keyword argument.
     #   The SocketIO server will only do SocketIO connections on URIs
     #   starting with this resource. So, using "socket.io" as your
     #   resource means that the SocketIO server expects its special
     #   connections to come in at `http://domain.com/socket.io/foo/`.
     # The default on both the Python side and the JavaScript side
     #   is "socket.io", and this is probably the best choice. It's possible
     #   to use something else, but it has to match everywhere and most
     #   likely won't be very DRY unless you jump a lot of hoops.
     socket_io_server = SocketIOServer(
         (kwargs['host'], kwargs['port']),
         application,
         resource='socket.io',
         policy_server=True,
     )
     
     # Set up the socket io server to actually serve; use the
     # auto-reloader if desired.
     use_reloader = kwargs['use_reloader']
     if use_reloader:
         spawn(reload_watcher)
     
     # Run the socket.io server within a try/except block
     # (so that if it is shut down, it can be restarted).
     try:
         socket_io_server.serve_forever()
     except KeyboardInterrupt:
         global _server_should_reload
         if _server_should_reload:
             # Set my "should reload" variable back to False.
             _server_should_reload = False
             
             # Kill the server.
             socket_io_server.kill()
             socket_io_server = None
             
             # Now, reload a new server.
             print '\nReloading server...'
             restart_with_reloader()
         else:
             print '\r\n\n'
             sys.exit(0)
开发者ID:agend07,项目名称:pycon2013-socketio,代码行数:67,代码来源:runserver.py


注:本文中的socketio.server.SocketIOServer.kill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。