hii i need the complete answers
Lab 9: A Web Server in Java
A web server is a server program that waits for incoming request on the HTTP port and acts on those to send the contents of local files back to the requester. It can be implemented in just a few dozen lines of code. The lab assignment here is part of the code for a web server.
Your Lab 9 assignment is to write a program that opens a server socket on the http port, port 80, and listens for requests from web browsers. You echo the requests, but don’t act on them.
I suggest that you split the code into two classes to better show what’s happening. The first class is the main program. It instantiates a server socket on the port 80. The code then should do an accept() on the server socket, waiting for the client connections to come in. When one does come in, the program should create a new object to deal with that one connection. You should have a method in this new object that would process a client request (getRequest). This new object is basically passed the socket object returned by the accept() method as an argument. It will create its InputStreamReader and DataOutputStream on the socket. Then, it should use the getRequest method to read bytes sent by the client on this socket and printout line by line. Each line should start with a text such as “got:” HTTP is a line-oriented protocol. This way, we could observe what the client sent to the server.
Please study relevant pages on chapter 9 of your textbook to learn more about accept() method and the ServerSocket.
Finally, you can test your server by using any web browser! Just start up your browser and direct it to the computer where you are running your server. That is your “localhost”.