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...
-
To regulate its output flow, a router implements a weighted queueing scheme with three queues at the output port. The packets are classified and stored in one of these queues before being...
-
Using the figure in the Application "A Semiconductor Integrated Circuit Isoquant," show that as the firm employs additional fixed-proportion technologies, the firm's overall isoquant approaches a...
-
Go to the books companion website and use information found there to answer the following questions related to The Coca-Cola Company and PepsiCo, Inc. (a) What are the amounts of Coca-Colas and...
-
An option's premium is 1.50 and has a delta of 40 with an underlying future at 100. If the underlying future moved from 100 to 102, what would the option's new premium be based on delta?
-
Below is the Trial balance of Miss Piggy & Kermit Inc. after his first years trading: Miss Piggy & Kermit Inc Trial Balance as of 30 June 20X8 Dr. Cr $ $ Revenue 99,082 Purchases 71,409 Rent...
-
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,...
-
You are holding a shopping basket at the grocery store with two 0.62-kg cartons of cereal at the left end of the basket. The basket is 0.61 m long. Where should you place a 1.9-kg half gallon of...
-
A landlord must be given reasonable time to make repairs after being notified of the condition needing repair. True False
-
To frequent trespassers who use only a limited area of their land, possessors owe 1. no duty of care. 2. a limited duty of care. 3. the same care they owe an invitee. 4. none of the above.
-
Suppose that prisons historically have required inmates to perform, without pay, various cleaning and food preparation jobs within the prison. Now, suppose that prisoners are offered paid work in...
-
The applicability of the attractive-nuisance doctrine depends on the age, experience, and intelligence of a child. True False
-
Landlords have a duty to protect a tenants invitees and licensees from dangers of which the landlord is aware but that the tenant has no reason to know about. True False
-
List eight ways you can explore career opportunities while still in college.
-
A container holds 2.0 mol of gas. The total average kinetic energy of the gas molecules in the container is equal to the kinetic energy of an 8.0 10-3-kg bullet with a speed of 770 m/s. 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...
-
In relational model, how to distinguish different keys (primary key,superkey, foreign key and so on)?
-
how to transform this from an EERD to a relational model diagram. Attribute_1-1A Attribute_1-1B Attribute_1-1 Attribute_1-1C Attribute_1-2 Entity 1 FK3 (M,M) Attribute_R_1-2-1 Rel_1-2 Attribute_2-1...
-
why is cardinality important to a relational database model? How is it usually defined and what types of GIS analysis operations is it particularly important to? Provide specific examples in your...
Study smarter with the SolutionInn App