views:

228

answers:

1

What is the difference between BaseHTTPServer and SimpleHTTPServer? When and where should i use these?

+3  A: 

BaseHTTPServer is a HTTP server library. It understands the HTTP protocol and let's your code to handle requests. It doesn't have any "logic" on it's own. SimpleHTTPServer is built on top of BaseHTTPServer and handles requests in a similar way normal HTTP servers do, i.e. serve files from the file-system. In most cases you will want only BaseHTTPServer, as a base for implementing some development server for a web application.

If you are interested in working on a web application, not writing a HTTP server, you are probably looking for the WSGI interface. It allows you to write web aplications without depending on a specific server. There are also multiple frameworks that simplify the process.

Lukáš Lalinský
Just to add, SimpleHTTPServer is pretty handy too. Just fire up with $python -m SimpleHTTPServer, and you are serving your files using HTTP!
Amit
i am creating an simple web gui for my apllication and i dont want to use frameworks like twisted,etc. is it possible to use wsgi with the builtin http server?
Sriram
There is `BaseHTTPServer` based WSGI server in `wsgi.simple_server`. But the advantage of WSGI is that you can use any WSGI server you want. You can use for example the WSGI server from CherryPy, or even Twisted, without writing CherryPy or Twisted specific code.
Lukáš Lalinský