In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to achieve python static web server, I hope you have something to gain after reading this article, let's discuss it together!
1. Write TCP server program.
2. Get the http request message data sent by the browser.
3. Read the fixed page data, assemble the page data into HTTP response message data and send it to the browser.
4. After the HTTP response message data is sent, close the socket that serves the client.
Example
# time: 2021-10-21 20:38import socket if _ _ name__ ='_ _ main__': # create tcp server socket tcp_server_socket = socket.socket (socket.AF_INET, socket.SOCK_STREAM) # set port number reuse, program exit port immediately release tcp_server_socket.setsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR) True) # bind port number tcp_server_socket.bind ((", 8080)) # set to listen tcp_server_socket.listen (128C) while True: # wait to accept the connection request new_socket from the client, ip_port = tcp_server_socket.accept () # the code is executed so far Indicates that the connection was established successfully recv_client_data = new_socket.recv (4096) # Decoding binary data recv_client_content = recv_client_data.decode) print (recv_client_content) # response line response_line = "HTTP/1.1 200 OK\ r\ n" # response header Response_header = "Server: py1.0\ r\ n" # Responder response_body = "Hello Guys! "# splicing response message response_data = (response_line + response_header +"\ r\ n "+ response_body). Encode () # send data new_socket.send (response_data) # shutdown service and client socket new_socket.close () have finished reading this article I believe you have a certain understanding of "how to implement python static web server". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.