Web server that returns fixed data

Source: Internet
Author: User

Import Socketdef handle_client (Socket_con): "" "receives the request from the client and receives the request message, parses, returns" "" # server receives the client's request message requests = S OCKET_CON.RECV (4096). Decode () print (request) # Server splicing response message and reply Response_line = ' http/1.1 ok\r\n ' Response_hea d = ' Server:skylark 2.0\r\n ' response_head + = ' content-type:text/html;charset=utf-8\r\n ' response_body = ' This is what is displayed!\r \ n ' response = response_line + Response_head + ' \ r \ n ' + response_body Socket_con.send (Response.encode ()) Socket_c On.close () def main (): # The server creates the socket Socket_listen = Socket.socket (socket.af_inet, socket) responsible for listening. SOCK_STREAM) # Set port reuse socket_listen.setsockopt (socket. Sol_socket, SOCKET. SO_REUSEADDR, True) # binds the Listening port socket_listen.bind ((' ', 8888)) # Set the listening queue Socket_listen.listen (128) # through the loop different accept please Ask while True: # accept () returns a tuple (socket object, address info) Socket_con, Socket_con_adds = Socket_listen.a        Ccept () # Print a hint message in print (' Client: ', Socket_con_adds, ' Connect successfully! ') # using functions to handle client sendsInformation Handle_client (socket_con) if __name__ = = ' __main__ ': Main () 

  

Web server that returns fixed data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.