Answer the question
In order to leave comments, you need to log in
An asynchronous HTTP server without the use of ready-made web timeworks. Python 3 http.server. How?
I have a server:
from http.server import BaseHTTPRequestHandler, HTTPServer
class Server(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("Hello, World!".encode("utf-8"))
def do_POST(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("POST!".encode("utf-8"))
webServer = HTTPServer(("", serverPort), Server)
print(f"Server started at http://localhost:{serverPort}")
try:
webServer.serve_forever()
except KeyboardInterrupt:
webServer.server_close()
print("Server stopped.")
webServer = ThreadingHTTPServer(("", serverPort), Server)
webServer = HTTPServer(("", serverPort), Server)
Answer the question
In order to leave comments, you need to log in
Why reinvent the wheel? There are a bunch of servers, one of the most famous is nginx
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question