Question
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm
1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may choose a port like 5678 and hard code it in both client and server programs. (Hints: for testing both programs on the same computer, you may want to put client program and server program at two different directories. Do NOT hard code the file name CS3700.htm!) The ending signature of the entity body in the HTTP response message for the case 200 OK: o When the HTTP Server program sends a HTTP response message out, it pads four continuous blank lines, i.e., , to the end of the .htm file as the ending signature of the entity body. o When the HTTP Client program read the HTTP response message line by line, it counts the number of continuous lines that are empty strings (NOT a null string). Once such number reaches 4, the entity body has been fully received. o It is assumed that the .htm file does not include such ending signature (in the real practice, length of the entity body may be included in the head line and used to determine the end of an entity body). HTTP Client Program: 1. Display messages on the standard output to ask the user to input the DNS name/ip of your HTTP server. 2. Buildup the TCP connection to your HTTP server with the Host Name input by User at the given port, and display the RTT of establishing this TCP connection in millisecond (the difference between the moments right before and after creating the socket object). Catch the exception, terminate the program, and display error messages on the standard output if any. 3. Display messages on the standard output to ask the user to input the HTTP method type, name of the htm file requested, HTTP Version, and User-Agent, respectively (separately please!). (hint: all inputs can be strings.) 4. Use the above inputs from user to construct ONE HTTP request message and send it to the HTTP server program over the TCP connection. Your HTTP request message only needs to include the following lines. (The correctness of the format will be checked by the instructor): The request line (hint: the URL should include a / in front of the htm file name) The header line for the field Host: The header line for the field User-Agent: 5. Receive and interpret the HTTP response message from the HTTP Server program line by line, display the RTT (File Transmission Time may be included) of HTTP query in millisecond (the difference between the moment right before HTTP request is sent and the moment right after HTTP response is received) as a single line (e.g., RTT = 1.089 ms), display the status line and header lines of the HTTP response message on the standard output, and save the data in the entity body to a .htm file to local directory if there is any. (Hint: (a) When one empty string (NOT a null string!) is read the FIRST TIME, it indicates the header lines are over and the entity body is going to start next line if the case is 200 OK.) 6. Display a message on the standard output to ask the User whether to continue. If yes, repeat steps 3 through 6. Otherwise, close all i/o streams, TCP connection, and terminate the Client program.
This was given to me
import java.io.*; import java.net.*;
public class TCPClient { public static void main(String[] args) throws IOException {
Socket tcpSocket = null; PrintWriter socketOut = null; BufferedReader socketIn = null;
if (args.length != 1) { System.out.println("Usage: java TCPClient
BufferedReader sysIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; String fromUser;
while ((fromUser = sysIn.readLine()) != null) { System.out.println("Client: " + fromUser); socketOut.println(fromUser); if ((fromServer = socketIn.readLine()) != null) { System.out.println("Server: " + fromServer); } else { System.out.println("Server replies nothing!"); break; } if (fromUser.equals("Bye.")) break; }
socketOut.close(); socketIn.close(); sysIn.close(); tcpSocket.close(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started