import socketimport reimport multiprocessingclass WSGIServer(object): def __init__(self): # Create a socket self.tcp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.tcp_server_socket .setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Binding self.tcp_server_socket.bind(('', 7890)) # Listening socket self.tcp_server_socket.listen(128) def service_client(self, new_socket): # Receive the request sent by the browser request = new_socket.recv(1024).decode('utf8') request_line = request.splitlines() print("") print(">" * 20) print(request_line) file_name = " "ret = re.match(r'[^/]+(/[^ ]*)', request_line[0]) if ret: file_name = ret.group(1) if file_name =='/': file_name = ' /index.html' # Return the data in http format to the browser try: f = open('./html' + file_name,'rb') except: response ='HTTP/1.1 404 NOT FOUND ' response +=' ' response +='file not found!' new_socket.send(response.encode('utf8')) else: html_content = f.read() f.close() response ='HTTP/ 1.1 200 OK ' response +=' ' new_socket.send(response.encode('utf8')) new_socket.send(html_content) # Close the connection new_socket.close() def run(self): while True: # Wait for the connection of the new client new_socket, client_addr = self.tcp_server_socket.accept() # Serve this client p = multiprocessing.Process(target=self.service_client, args=(new_socket,)) p.start() new_socket.close() # Close the socket self.tcp_server_socket.close()def main(): wsgi_server = WSGIServer() wsgi_server.run()if __name__ =='__main__': main()
Simple object-oriented -Web server
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2821 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC