Mar-27-2021, 03:10 PM
I am using the socketserver as the example below to establish connections in the tcp layer and to be able to have interactions with the http data processing (status, headers, html ...), I believe that to start structuring a web server I must obtain the protocol (http , https and ports), how can I get (http and https) ?
import socketserver class MyTCPHandler(socketserver.BaseRequestHandler): def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).decode() # self.client_address tuple ( ip and port ) self.client_address[0] # self.data.split, method splits a string into a list self.a_data = self.data.split() # print request headers print(self.a_data) if __name__ == "__main__": HOST, PORT = "", 8000 # Create the server, binding to localhost on port 9999 with socketserver.TCPServer((HOST, PORT), MyTCPHandler) as server: # Activate the server; this will keep running until you # interrupt the program with Ctrl-C server.serve_forever()