A Java implementation of Simple HTTP Web Client(/Web Browser) and a Multithreaded Web Server.
- Programming Language: Java (jdk 11.0.1)
- IDE: Eclipse Photon
- OS: Windows 10
- Command Line Interface: Windows command prompt used to run/test the program
-
server: Contains Web Server implementation
WebServer.java
: Implements a mulithreaded server and initializes a serverSocket to listens to the client requests. Once a client is connected, the processing is handed over to a separate thread HttpRequest.Default Port number is set to 8081HttpRequest.java
: Request is handled by this method in a separate threadindex.html
: A default html file which is sent to the client in case a GET request contains "/" filepath i.i if no file path is mentioned.demo2.html
: A additional html file which can be requested to display.
-
client: Contains Client Implementation
WebClient.java
: Implements a web client which sends a HTTP request to the server. It mentions the host name,port number and path to be requested.
-
Compile and execute WebServer.java (Port is set to 8081)
-
Compile and execute WebClient.java You can pass the arguments in the following fashion- i. hostname (localhost) ii.hostname portNumber (localhost 8081) iii. hostname portnumebr filePath (localhost 8081 server/demo2.html)
-
You can also send the request through web browser in the following manner- i. localhost:8081 ii.localhost:8081/demo2.html
Cached files are stored in the main folder.
-
Compile all server and client code located in separate directories.
cd server
javac *.java
cd client
javac *.java -
Run web server in server directory.
java WebServer
-
Run web client in client directory by passing at least one argument i.e. serverHost/IP address. Other optional arguments are port and the path of the file to request from the server.
-
java WebClient localhost
-
java WebClient localhost 8081
-
java WebClient localhost server/demo2.html
-
-
All requested file paths must be relative to the
HttpRequest.java
class. If not, 404 error will be returned.
- Book: Computer Networking. A Top Down Approach. Fifth Edition by James F. Kurose, Keith W. Ross. Chapter 2.
- Thread Tutorial from Oracle 3.Reference: Computer Network Textbook by Kurose and Ross: Chapter 2 Socket Assignment 1
- Socket Communications from Oracle
- https://www.geeksforgeeks.org/socket-programming-in-java/
- https://www.binarytides.com/java-socket-programming-tutorial/