Skip to content

joncooknmsu/SimpleWebserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleWebserver

A simple Java web server skeleton. This code purposely does not implement much functionality to serve actual pages or other files because this is left as an assignment to students.

The server is composed of two classes: WebServer is the main driver class and an object of this class creates a socket and listens on the socket for incoming client connections. When a client connects, the WebServer object creates a WebWorker object, runs it in its own Thread, and hands the client connection off to this worker object.

One WebWorker_ object handles one client connection, and only one HTTP request, because the worker object replies with a "Connection: close" HTTP response line. This is highly inefficient but it is simple, and keeps the code simple.

The code is mostly javadoc'd, so you can generate code documentation.

Running the program

As written, this program accepts zero or one command line argument, which is a port number to open a socket on. The port defaults to 8080.

"java WebServer" will run the server on port 8080.

"java WebServer 9000" will run the server on port 9000.

If you run it on your local machine, point your browser to http://localhost:8080/

If you run the server on a remote machine, point your browser to http://machinename.domain:8080/

If you run it on a remote machine and your browser does not get a response, it is possible that your ISP or some network entity in between you and the remote machine is blocking high port numbers.

About

A simple Java web server

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages