zoukankan      html  css  js  c++  java
  • tornado httpserver

    这是一个非阻塞的,单线程的httpserver。这个类一般是不会被应用程序直接调用的,它一般是被上层的tornado.web.Application.listen方法调用,因为这个listen方法是这样定义的

     def listen(self, port, address="", **kwargs):
            """Starts an HTTP server for this application on the given port.
    
            This is a convenience alias for creating an `.HTTPServer`
            object and calling its listen method.  Keyword arguments not
            supported by `HTTPServer.listen <.TCPServer.listen>` are passed to the
            `.HTTPServer` constructor.  For advanced uses
            (e.g. multi-process mode), do not use this method; create an
            `.HTTPServer` and call its
            `.TCPServer.bind`/`.TCPServer.start` methods directly.
    
            Note that after calling this method you still need to call
            ``IOLoop.current().start()`` to start the server.
    
            Returns the `.HTTPServer` object.
    
            .. versionchanged:: 4.3
               Now returns the `.HTTPServer` object.
            """
            # import is here rather than top level because HTTPServer
            # is not importable on appengine
            from tornado.httpserver import HTTPServer
            server = HTTPServer(self, **kwargs)
            server.listen(port, address)
            return server

    @staticmethod和@classmethod,实例方法的区别

    @classmethod 是一个函数修饰符,它表示接下来的是一个类方法,而对于平常我们见到的则叫做实例方法。 类方法的第一个参数cls,而实例方法的第一个参数是self,表示该类的一个实例。因为持有cls参数,可以来调用类的属性,类的方法,实例化对象等,避免硬编码。

    静态方法则没有,它基本上跟一个全局函数相同,一般来说用的很少,只是包含在类结构中,实际跟类没有关系,要调用到这个类的一些属性方法,只能直接类名.属性名或类名.方法名。

    版本4.0的变化

    HTTPRequest类被移动到了tornado.httputil.HTTPServerRequest,原来的名字还是可以使用的

    HTTpServer默认支持keep-alive连接,自动支持HTTP/1.1,当客户端要求keep-alive连接时变为HTTP/1.0

  • 相关阅读:
    MySQL 视图的作用
    基类一定要设置虚析构函数,否则会内存泄露
    Delphi ISO,包括D2010DXE6比较全面的测评(绝美PDF)
    一些最重要的PHP数组函数
    没有虚函数情况下的函数覆盖(以原始指针的类型为准)
    使用Mono.Cecil辅助ASP.NET MVC使用dynamic类型Model
    持续集成(CI) TeamCity实战概览
    对.Net状态保持机制和并发问题的思考
    Windows Communication Foundation 概述
    Welcome to HDU Online Judge System
  • 原文地址:https://www.cnblogs.com/suntp/p/6616029.html
Copyright © 2011-2022 走看看