#-*-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