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!

  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import string
  5. import SimpleHTTPServer
  6. import SocketServer
  7.  
  8. if len(sys.argv) != 3:
  9.     sys.exit(1)
  10.  
  11. addr = sys.argv[1]
  12. port = string.atoi(sys.argv[2])
  13.  
  14. handler = SimpleHTTPServer.SimpleHTTPRequestHandler
  15. httpd = SocketServer.TCPServer((addr, port), handler)
  16. print "HTTP server is at: ", addr, port
  17. 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. 

Alex on April 23, 2010 (Friday) 20:13 CST+0800

sadf 
Name:
Contents: (MarkDown Grammer)
Site:
E-Mail: (Private)
CAPTCHA: CAPTCHA
Preview: