Python Based HTTP Server
December 07, 2008 (Sunday) 15:29 CST+0800
To share files on the Internet, we could use NFS, ftp, samba, but the most popular onw is HTTP. So just /etc/init.d/apache2 start will start the Apache server. But as known to all, Apache is huge in size, so usually no need to reconfigure it for sharing a file. Write one HTTP server in C? 100+ lines of code will be needed to archive that goal.
We have python, the best way and the only best way!
-
#!/usr/bin/env python
-
-
import sys
-
import string
-
import SimpleHTTPServer
-
import SocketServer
-
-
if len(sys.argv) != 3:
-
sys.exit(1)
-
-
addr = sys.argv[1]
-
port = string.atoi(sys.argv[2])
-
-
handler = SimpleHTTPServer.SimpleHTTPRequestHandler
-
httpd = SocketServer.TCPServer((addr, port), handler)
-
print "HTTP server is at: ", addr, port
-
httpd.serve_forever()
Comments
Alex on March 07, 2010 (Sunday) 01:19 CST+0800
How do I wish to get back!Alex on April 23, 2010 (Friday) 20:11 CST+0800
I'll be back, I'll be back...I promise.


and Solaris 11.