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...
-
George owed Keith $800 on a personal loan. Neither the amount of the debt nor Georges liability to pay the $800 was disputed. Keith had also rendered services as a carpenter to George without any...
-
Styles Salon had \($87,000\) of total assets and \($52,000\) of total stockholders equity at December 31, 2010. At December 31,2011, Styles Salon had assets totaling \($153,000\) and stockholders...
-
Imagine that you are holding 5,000 shares of stock, currently selling at $40 per share. You are ready to sell the shares but would prefer to put off the sale until next year for tax reasons. If you...
-
Sunland Company's sales budget projects unit sales of part 1987 of 9,400 units in January, 11,000 units in February, and 12,500 units in March. Each unit of part 198Z requires 4 pounds of materials,...
-
WRITE IN PYTHON AND IN THE GIVEN CODE coderbyte medium Back-end Challenge In the Python file, write a program to perform a GET request on the route Time left: Unlimited time...
-
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,...
-
Match each of the key terms above to the definition that best fits it. Object-based interaction ____ A method by which users interact with information systems. ____ A humancomputer interaction method...
-
EZ-Tax is a tax accounting practice with partners and staff members. Each billable hour of partner time has a $600 budgeted price and $300 budgeted variable cost. Each billable hour of staff time has...
-
A baseball is hit almost straight up into the air with a speed of 32m/s. Estimate (a) how high it goes, (b) how long it is in the air. A falling stone takes 0.41 s to travel past a window 2.8 m tall....
-
(a) Three point charges, A = 2.15 C, B = 6.60 C, and C= -4.25 UC, are located at the corners of an equilateral triangle as in the figure above. Find the magnitude and direction of the electric field...
-
A DTMF decoding system needs two pieces: a bandpass filter to isolate individual frequency components, and a detector to determine whether or not a given component is present. The detector must...
-
net; Layer L-1 JE Yj ,(L-1) j,i and neti Yi Layer L (last hidden layer) (1) =-y.8k where &k= f'(netk) (tk - Yk) (L) awl,k Using the gradient descent method, assuming that E = k(yk - tk), then prove...
-
Describe authentication and authorization. Which depends on the other? How and why are these processes more complex in a networked organization than in an organization that supports all information...
-
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...
-
A physiotherapist purchased 7 rolls of resistance bands and 12 therapy balls for a total cost of $406. A second purchase, at the same prices, included 9 rolls of resistance bands and 14 therapy...
-
The Mentor company manufactures butcher block tables. Each table requires the following direct materials, direct labor and overhead. Standard Quantity 2" clear maple 12 db. Ft. Direct labor 2 hours...
-
Vintage is a public company that prepares financial statements inaccordance with IFRS Standards. Its reporting date is 31 March 20X3. Vintage entered into a contract with a customer to supply...
Study smarter with the SolutionInn App