Modify, compile, and test the client program in Table 25.17 and the server program in Table 25.16
Question:
Modify, compile, and test the client program in Table 25.17 and the server program in Table 25.16 to allow the client to provide the pathname of a short file stored on the server host. The server needs to send the contents of the short file as a string of characters. The client stores the file at the client host. This means simulating a simple file transfer protocol.
Table 25.16
Table 25.17
Transcribed Image Text:
Table 25.16 A simple TCP server program 1 import java.net.*: 2 import java.io.*; 3 4 public class TCPServer 6. Socket sock; InputStream recvStream; OutputStream sendStream; 7 8 String request; 10 String response; 11 12 TCPServer (Socket s) throws IOException, UnknownHostException 13 14 sock = s; recvStream = sock.getInputStream (): sendStream = sock.getOutputStream (); 15 16 17 18 19 void getRequest () 20 21 try 22 { int dataSize; 23 24 while ((dataSize = recvStream.available () ==0); 25 byte [] recvBuff = new byte [dataSize]; 26 recvStream.read (recvBuff, 0, dataSize): 27 request = new String (recvBuff, 0, dataSize); 28 29 catch (IOException ex) 30 31 System.err.println ("IOException in getRequest"); 32 33 34 35 void process() 36 { 37 // Add code to process the request string and create response string. 38 39 40 void sendResponse () 41 42 try 43 { byte [] sendBuff = new byte [response.length (O): sendBuff = response.getBytes (); 44 45 46 sendStream.write (sendBuff, 0, sendBuff.length); 47 48 catch (IOException ex) 49 50 System.er.println ("IOException in sendResponse"); 51 52 53 54 void close () 55 56 try 57 58 recvStream.close (); 59 sendStream.close (); 60 sock.close (); 61 62 catch (IOException ex) 63 64 System.err.printin ("IOException in close"); 65 66 67 68 public static void main (String [] args) throws IOException 69 { 70 final int port = ...; // Provide port number 71 ServerSocket listenSock = new ServerSocket (port); 72 while (true) 73 74 TCPServer server = new TCPServer (listenSock.accept (): 75 server.getRequest 0; 76 server.process (; server.sendResponse (); 77 78 server.close (); 79 80 } // End of main 81 }// End of TCPServer class
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (8 reviews)
This assignment shows how we can add some classes to the server and client site to simu...View the full answer
Answered By
HARSH RANJAN
Taken classes at college to graduates, Also worked as an expert to a freelancer online question-solving portal for more than 8 months with an average rating greater than 4.2 out of 5.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Modify, compile, and test the client program in Table 25.13 and the server program in Table 25.12 to do the following: The client program needs to read the request string from a file and store the...
-
The speed of a file transfer from a server on campus to a personal computer at a students home on a weekday evening is normally distributed with a mean of 60 kilobits per second and a standard...
-
Server Farm Inc. (SFI) needs to upgrade its server computers. Company management has identified the following two options: (1) Shift to a Windows based platform from its current Unix-based platform,...
-
Selecting the best-suited HVAC system depends on factors such as: cost and availability of the energy source; appliance or system efficiency; cost to purchase, install, and maintain the appliance or...
-
On February 14, 2016, Isabelle Moretti, Aida Kam, and Channade Fenandoe start a partnership to operate a marketing consulting practice. They sign a partnership agreement to split profits in a 2:3:4...
-
In the early 1990s, there were approximately 5 billion people in the world. Plous (1993, p. 5) asked readers to estimate how wide a cube-shaped tank would have to be to hold all of the human blood in...
-
Calculate the doubling time for annual percentage increases of \(2 \%\) and \(10 \%\), assuming an exponential growth function.
-
Madson Corporations balance sheet at December 31, 2013, is presented below. During January 2014, the following transactions occurred. Madson uses the perpetual inventory method. Jan. 1 Madson...
-
3. Depreciation on non-current assets is as follows: Vehicles: 20% on the fixed line method Buildings: 30% on the straight line method Machines: 25% on the diminishing balance method Land is not...
-
Fill in the blanks for the ABC analysis process map. Based on the process map, calculate the assigned indirect costs using the traditional method. Explain the pros and cons of this in comparison to...
-
Write a method in Java to extract the prefix of an address (as an integer) given a string representing a CIDR notation in the form x.y.z.t/n.
-
A new application is to be designed using the client-server paradigm. If only small messages need to be exchanged between the client and the server without concern for message loss or corruption,...
-
Evaluate the integral I in Example 1, Sec. 41, using this representation for C: z = 4 y2 + iy (2 y 2). (See Exercise 2, Sec. 39.)
-
The Kidz Klothing store ordered a line of snowsuits at $60 each, less a trade discount of 8%. The selling price is marked up to allow for overhead expenses of 15% of the cost price, and profit of 25%...
-
After graduation, you find that you have an excess of $4,750 left over from scholarships and internship earnings. Rather than spend the money on something nice for yourself, you decide to use this as...
-
You are offered an annuity that will pay you $25,000 at the end of each year for the rest of your life. If the applicable market interest rate is 3.3%, and you plan. on living until age 90, what...
-
Estimate the instantaneous rate of change of f(x)=3x+2_atx=-2.
-
"Paula is a social worker in a fostercare agency. She has been working with 9-year-old Rita, her foster mother, Flo, and biological mother, Stella, for three years. Rita was removed from her mother's...
-
A preliminary study suggests a benefit from green tea for those at risk of prostate cancer. The study involved 60 men with PIN lesions, some of which turn into prostate cancer. Half the men, randomly...
-
A fuel pump sends gasoline from a car's fuel tank to the engine at a rate of 5.88 10-2 kg/s. The density of the gasoline is 735 kg/m3, and the radius of the fuel line is 3.18 10-3 m. What is the...
-
Verify the conceptual model you created in Appendix B, problem 3. Create a data dictionary for the verified model.
-
Verify the conceptual model you created in Appendix B, Problem 4. Create a data dictionary for the verified model.
-
Bsed on the following query: SELECT EMP_LNAME, EMP_FNAME, EMP_AREACODE, EMP_SEX FROM EMPLOYEE WHERE EMP_SEX = F AND EMP_AREACODE = 615 ORDER BY EMP_LNAME, EMP_FNAME; What is the likely data sparsity...
-
Describe the phenomenon in current accounting practices that has been dubbed the Earnings Game in the article by Justin Fox. Why do companies play this game? Based off this article:...
-
On January 1, 2018, Bark Manufacturing Company Ltd. purchased a machine for $27,500, and expects to use the machine a total of 32,000 hours over the next four years. Bark set the residual value on...
-
Covid and post Covid Economic Recovery for each of the papers you are required to state the following : 1. what was the study about 2. what were the findings 3. list the research gaps and suggest new...
Study smarter with the SolutionInn App