"Important" How to build your own simple Web server

Source: Internet
Author: User

#-*-coding:utf-8-*-#python#Xiaodeng#CGI module#How to build your own simple Web server#use:#in the intranet, it is very useful to provide shared services for files, and after starting the Run Server command under CMD, other computers can also be accessed via URLs.#can achieve PDF, zip and other compressed files, EXE, APK and other software download services.## #搭建基本流程 # ##1. Assume that the directory of shared files is:/home/test,ip to #192.168.1.101" "How do I view my native IP? Import socketmyname = Socket.getfqdn (Socket.gethostname ()) myaddr = Socket.gethostbyname (myname) print myaddr" "#2. Run the following command under CMD:#CD C:\home\test#c:\\python27\python-m Simplehttpserver           #3. Open Browser, http://localhost: Port number/path to access server resources#such as: Access to http://192.168.1.101:8000, intranet other machines can also be accessed through the server's IP address#port number, default 8000#by default, the directory defined above has a index.html file, which is the default page, and if not, the directory is displayed as a list#4. Precautions:#in the intranet, file transfer is very convenient, 50mb/s is not a dream. However, concurrency is not supported and can only be downloaded by colleagues, but it is possible to write new modules to support concurrency. #http://www.wtoutiao.com/p/jffBpc.html#forkstaticserver.pyImportSocketImportSocketserverImportBasehttpserver fromSimplehttpserverImportSimplehttprequesthandlerclassForkinghttpserver (socketserver.forkingtcpserver): Allow_reuse_address= 1defServer_bind (self):"""Override Server_bind to store the server name."""SocketServer.TCPServer.server_bind (self) host, Port= Self.socket.getsockname () [: 2] Self.server_name=Socket.getfqdn (host) Self.server_port=PortdefTest (handlerclass=simplehttprequesthandler,serverclass=forkinghttpserver): Basehttpserver.test (Handlerclass, ServerClass)if __name__=='__main__': Test ()#Save the above code as a file forkstaticserver.py,#put in the directory of the Python standard library (on my Computer is/usr/lib/python2.7/forkstaticserver.py), later with the following command instead of the previous command, so the static file server is built to support concurrency!#build your own Web server-related libraries:ImportBasehttpserverImportSimplehttpserverImportCgihttpserver#Import Httpserver (present in Python3)

"Important" How to build your own simple Web server

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.