Created
August 14, 2013 12:18
-
-
Save yanmhlv/6230541 to your computer and use it in GitHub Desktop.
tornado http server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpserver | |
import tornado.web | |
import tornado.ioloop | |
def handle_request(request): | |
message = "You requested %s\n" % request.uri | |
request.write("HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % ( | |
len(message), message)) | |
request.finish() | |
class BaseHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write('Hello world') | |
app = tornado.web.Application([(r'/', BaseHandler)]) | |
#app.listen(5002) | |
server = tornado.httpserver.HTTPServer(handle_request, | |
#ssl_options=dict( | |
#certfile="foo.crt", | |
#keyfile="foo.key", | |
#cert_reqs=ssl.CERT_REQUIRED, | |
#ca_certs="cacert.crt") | |
) | |
http_server = tornado.httpserver.HTTPServer(app) | |
http_server.bind(5000, '0.0.0.0') | |
http_server.start(0) | |
#app.listen(5000, '0.0.0.0') | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment