Wednesday, June 07, 2006

Simple HTTP Server in Java

Just for fun (well, almost), I wrote my very own simple HTTP server in Java (download 100 KB ZIP) the other night. It uses Java5 features, and requires no external libraries. While it certainly does work and can serve a static website HTML+image site, it is of course NOT meant as a "real" web server, so do NOT use it - it's instructional, and it sure was fun to code!

PS: Almost eight years ago, I put online a Proxy Server written in C on my website, and to my big surprise, during all the years since, every now and then a CS student (presumably asked to write one for class, just like I had at the time), emails some questions... So just in case folks, if you found this page because you are looking for a cheap way out for your homework, by all means download and look at it - but then fix/improve it, and quoting the source and explaining your enhancements! And put a quick comment to this post below.

6 Comments:

Anonymous Anonymous said...

Hey good job! It was really helpful for me. I was looking for a simple single threaded web server.

06 December, 2006 23:23  
Anonymous Anonymous said...

Good this. I wrote my own version to support serving xml data from a DB over http to a flex application. But my C: drive bit the dust and I needed a replacement http server class rather than rewrite my own again.
Thanks for this. Saves me a lot of rework!

Chris

17 January, 2008 14:20  
Blogger Filirom1 said...

5 years later, I found your code and find it very usefull.

I added the dir listing feature and put the library on maven.

Here is the new source code : https://github.com/Filirom1/SimpleHTTPServer

Cheers

Romain

15 April, 2011 11:03  
Blogger Charles Dobson said...

I did a similar thing "Just for Fun" a while back too, learned alot about the HTTP protocol as a result and also about CGI, PHP and Java threads. I extended my simple server to enable PHP to be executed via CGI calls which could be used to build simple dynamic websites. Might be a useful link for anyone wanting to take your idea a step or two further. http://kcd.sytes.net/articles/simple_web_server.php

19 March, 2012 22:08  
Blogger Charles Dobson said...

This comment has been removed by a blog administrator.

19 March, 2012 22:09  
Blogger Michael Vorburger said...

Follow up on http://blog2.vorburger.ch/2012/08/simple-http-server-in-java-on-github.html now...

20 August, 2012 09:59  

Post a Comment

Links to this post:

Create a Link

<< Home