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...
-
Roenfeld Corp believes the following probability distribution exists for its stock. What is the coefficient of variation on the company's stock? State of the Economv Boom Normal Recession Probability...
-
Are facilities, offices, machinery, and equipment in good working condition?
-
Should all companies consider reducing their sales forces in favor of telemarketing? Discuss the pros and cons of this action. Many companies are realizing the efficiency of telemarketing in the face...
-
Strategy maps Grand Grocery developed a balanced Scorecard with six strategic objectives under the standard four performance perspectives, as follows: Learning and Growth Internal Processes Customer...
-
Alabama Atlantic is a lumber company that has three sources of wood and five markets to be supplied. The annual availability of wood at sources 1, 2, and 3 is 15, 20, and 15 million board feet,...
-
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,...
-
Peter's eamings are taxed at a rate of 15 percent by the personal income tax and at a combined rate of 7.45 percent by the Social Security and Medicare payroll taxes. Suppose that if Peter becomes...
-
Are investors too impatient in wanting returns from these investments? "Would Nordstrom be better off if it were owned by private investors, rather than as a publicly traded firm since this would...
-
how AI is used to discover new material, will it change the whole science environment?
-
QUESTION 1 Which one of the following statements is not part of the "bundle of rights" enjoyed by a fee simple owner of property? a. The right to possess the property b. The right to control what...
-
In order to pay his rent, Tom, a college student, has taken a job in the computer department of a local department store. His only responsibility is to answer telephone calls to the department, most...
-
How does database normalization impact data integrity and query performance in complex relational schemas ? Explain
-
An incident particle of charge q1 and kinetic energy E scatters off a heavy stationary particle of charge q2. (a) Derive the formula relating the impact parameter to the scattering angle. (b)...
-
Archangel Corporation prepared the following variance report. Instructions Fill in the appropriate amounts or letters for the question marks in the report. ARCHANGEL CORPORATION Variance...
-
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...
-
ABC Insurance Company reported the following information on its accounting statements last year: What was ABC 's expense ratio last year
-
Calculate the current ratio and the quick ratio for the following partial financial statement for Tootsie Roll Note: Round your answers to the nearest hundredth
-
Required information Skip to question [ The following information applies to the questions displayed below. ] Golden Corporation's current year income statement, comparative balance sheets, and...
Study smarter with the SolutionInn App