Rudimentary HTTP Server

This was an exam question.

This is a multi-threaded HTTP 0.9 server. It was not well-defined what the line termination conventions were, and so if one merely used the Java read line function the server might not work correctly on machine that do not use linefeed as newline. So I coded the input scanning as a StreamTokenizer with all control characters as terminators. This probably accepts a lot of broken stuff, but who will be sending us broken stuff? This server also crashes if asked for a file that does not exist. Clearly a production server would need more robustness, but I think this is minimal enough to read and grade given the fact that this is an exam question.

Note that this server does NOT create a new object when it first runs. Instead, it creates a new object whenver a new client connects. So the global control is in the static main routine. Also, instead of using buffered IO stream objects, I do the buffering myself, with a byte buffer whose size is set by BUFF_SIZE. This could be made a command line argument if desired. But I feel that this does satisfy the assignment requirements of using buffered IO while eliminating any character-at-a-time handling in the server code.

Back to ZBEN's home page.