Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 4 [20 marks). An echo server echoes back whatever it receives from a client. For example, if a client sends the server the string
Question 4 [20 marks). An echo server echoes back whatever it receives from a client. For example, if a client sends the server the string Hello there!, the server will respond with Hello there! Write an echo server using the Java networking API described in Section 3.8.1 of the textbook. This server will wait for a client connection using the accept() method. When a client connection is received, the server will loop, performing the following steps: . Read data from the socket into a buffer. Write the contents of the buffer back to the client. The server will break out of the loop only when it has determined that the client has closed the connection. The date server of Figure 3.27 of the textbook uses the java.io.BufferedReader class. BufferedReader extends the java.io.Reader class, which is used for reading character streams. However, the echo server cannot guarantee that it will read characters from clients; it may receive binary data as well. The class java.io.InputStream deals with data at the byte level rather than the character level. Thus, your echo server must use an object that extends java.io.InputStream. The read() method in the java.io.InputStream class returns -1 when the client has closed its end of the socket connection. Question 4 [20 marks). An echo server echoes back whatever it receives from a client. For example, if a client sends the server the string Hello there!, the server will respond with Hello there! Write an echo server using the Java networking API described in Section 3.8.1 of the textbook. This server will wait for a client connection using the accept() method. When a client connection is received, the server will loop, performing the following steps: . Read data from the socket into a buffer. Write the contents of the buffer back to the client. The server will break out of the loop only when it has determined that the client has closed the connection. The date server of Figure 3.27 of the textbook uses the java.io.BufferedReader class. BufferedReader extends the java.io.Reader class, which is used for reading character streams. However, the echo server cannot guarantee that it will read characters from clients; it may receive binary data as well. The class java.io.InputStream deals with data at the byte level rather than the character level. Thus, your echo server must use an object that extends java.io.InputStream. The read() method in the java.io.InputStream class returns -1 when the client has closed its end of the socket connection
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