Question: In this project, you will write a simple HTTP server (using ServerSocket class) that serves web browsers as its clients. This server is capable of
In this project, you will write a simple HTTP server (using ServerSocket class) that serves web
browsers as its clients. This server is capable of processing only one request (like Project 1).
Once your program starts, it opens a server socket with port number 9000, waiting for any client
connection. After the server starts, it displays (on servers side screen) servers ip address, port
number and the message that shows the server has started successfully.
Once the client makes a connection, the server must do the following;
1.
The server displays the message that the client sent on servers side screen.
2.
The server assembles the response message using the format that was shown the lecture
notes. The header lines are as follows
a.
HTTP/1.1 200 OK
b.
keep-Alive: timeout =10, max=100
c.
Content-Type: text/html
d.
Data Section
follows
i.
In this data section, you will simple return the string The connection to
the Web Server was made on
ii.
Data Section will be html format such as ...
When the client connects to your server, the client browser will display
Data Section
on the
screen. To connect to the server from the web browser, you will use
server ip address:port
number
in the address bar to request a connection.
Here is the server from project 1:
import java.io.IOException; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.util.Date;
public class Server {
public static void main(String[] args) throws IOException { ServerSocket listener = new ServerSocket(9000); try { while (true) { Socket socket = listener.accept(); try { PrintWriter out = new PrintWriter(socket.getOutputStream(), true); out.println(new Date().toString()); } finally { socket.close(); } } } finally { listener.close(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
