In many cases, we will need a web server, but you may not know how to implement it yourself. It is ok to implement it. Just use Twisted and the method is below. It doesn't need to be too much to realize the advantages of the Web server itself, mainly to control the specific implementation. You can also interact in accordance with your own habits.
And Twisted is written in C below tcp, ip and udp should be a mixture of C and Python, and httpsmtp and so on are Python, which can be well extended.
Let's look at a concrete example:
First you need to edit the name of a file ending with html and put it in your htm directory.
Then create a file in the upper directory of htm, the file name is web.py, the content is as follows:
Code:
[code:1:79fbd7e444]< Br>
PORT=80# This is 80. If your port is occupied, change to other
fromtwisted.web.resourceimportResource
fromtwisted.webimportserver
fromtwisted.webimportstatic
fromtwisted.internetimportreactor
classReStructured(Resource):
def__init__(self,filename,*a):
self.rst= Open(filename).read()
defrender(self,request):
returnself.rst
resource=static.File('./htm/')< Br>
resource.processors={'.html' :ReStructured}
resource.indexNames=['index.html']
reactor.listenTCP(
PORT,
server.Site(resource)
)
reactor.run()
[/code:1:79fbd7e444]
Enter the directory under the console and type pythonweb.py, then hit Open a browser, enter http://127.0.0.1, see your site?
Now try to see how to achieve it, methods and operations are simple, you can do it step by step It is a good thing to be able to implement the web server by yourself. There are many advantages. If you need it, you may wish to try it.
Implementing copy and paste function in CMD command line and PowerShellFriends who often us
Our computer has been used for a long time, and the computers disk will produce a certain amount of
For the computer, the longer the use time, the slower the speed back, and the space will be smaller
After we installed the system, we didnt install all the system components. Because these components
The image printed in the Excel form is very vague how to solve it?
Windows, Centos dual system can not start the problem
Experts quickly diagnose computer viruses have a trick
Full resolution of disk cache write method
Comprehensive analysis of RUNDLL32.EXE file
How to effectively delete a system in a dual system?
Solution to the problem of insufficient memory under different systems
Different bios should use different entry methods
Teach you how to correctly distinguish between 32-bit and 64-bit operating systems
What should I do if the installation driver prompts "File Loss" causes the installation to fail?
Win10 boot black screen long time, slow boot solution
How to do the installation of win10 actually used 30G?
How to set Win10 not standby Win10 set computer does not stand by method
What should I do if I need permission to perform this operation under win8 system?
The trick of disabling the folder option under xp
Windwos7 tips - aero settings and window colors
Windows7 system change time zone method graphic tutorial
Win8 how to upgrade and reload IE10 plugin
What is going on when the font of the webpage suddenly becomes smaller?
How to set the modified default sorting in the Win8.1 system application menu?