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 simulate a local DNS client and server. The server has a short table made of two columns, domain name and IP address. The client can send two types of requests: normal and reverse. The normal request is a string in the format “N:domain name”; the reverse request is in the format “R:IP address”. The server responds with either the IP address, the domain name, or the message “Not found.”
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: 86% (15 reviews)
This assignment shows how we can use the TCP client and server program defined in the text to s...View the full answer
Answered By
Mugdha Sisodiya
My self Mugdha Sisodiya from Chhattisgarh India. I have completed my Bachelors degree in 2015 and My Master in Commerce degree in 2016. I am having expertise in Management, Cost and Finance Accounts. Further I have completed my Chartered Accountant and working as a Professional.
Since 2012 I am providing home tutions.
3.30+
2+ 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...
-
Can a computer have two DNS names that fall in different top-level domains? If so, give a plausible example. If not, explain why not.
-
Modify the program Coin Tosses to toss coin n times and print out after every 100 tosses the proportion of heads minus 1/2. Do these numbers appear to approach 0 as n increases? Modify the program...
-
If an investor holds a credit-linked note and the credit event does not occur, the investor receives: A. All promised cash flows as scheduled. B. All coupon payments as scheduled but not the par...
-
Ajax Architects is a partnership with three partners. On January 31, 2017, the three partners, Tova Radzik, Sela Kopel, and Etti Falkenberg, have capital balances of $98,000, $79,000, and $47,000,...
-
Explain why the story about George D. Bryson, reported in Example 17.1, is not all that surprising.
-
In 2009, a group of environmentalists approached the Boulder City Council with a request to deny an application to continue operating the local coal-fired \(200 \mathrm{MW}\) power plant in order to...
-
The return on investment measure may be biased in favor of divisions with older plant and equipment. Explain.
-
Beta Ltd is a diversified entity whose reporting date is 31 December. The entity uses the perpetual inventory system and the following information, relating to the acquisition of trading inventory,...
-
XYZ is a calendar-year corporation that began business on January 1, 2018. For the year, it reported the following information in its current-year audited income statement. Notes with important tax...
-
Write a method in Java to extract the IP address (without the prefix) as a string in dotted-decimal notation from a string representing the CIDR notation (x.y.z.t/n).
-
Which of the following can be a source of data? a. A keyboard b. A monitor c. A socket
-
Rayya Co. purchases a machine for $105,000 on January 1, 2021. Straight-line depreciation is taken each year for four years assuming a seven-year life and no salvage value. The machine is sold on...
-
What is the Owner Equity amount for Ernesto's Skateboard Corporation that should be reported on its balance sheet? Cash $5,000 Cash Equivalents $10,000 Accounts Receivable $30,000 Inventory $10,000...
-
Instructions: Answer each question completely using the tools and concepts learned in the course. Your answers should demonstrate analytical rigor and should be clear and succinct (an exceptional...
-
The US economy grew more slowly in the second quarter than previously estimated a good sign for the Federal Reserve, which isattempting to cool demandto bring down price increases. Gross domestic...
-
Ken Young and Kim Sherwood organized Reader Direct as a corporation; each contributed $59,000 cash to start the business and received 4,000 shares of stock. The store completed its first year of...
-
World folklore and history are replete with examples that involve economics principles. A sizable portion of these concern both military and nonmilitary endeavors that proved costly in terms of lives...
-
In Exercise 4.134 on page 279, we used the data in Table 6.13 to conduct a randomization test to see if there was evidence that electrical stimulation of the brain helped people solve a problem that...
-
Determine the optimal use of Applichem's plant capacity using the Solver in Excel.
-
Create an Order data entry screen, using the ORDERS and ORDER_LINE tables in the RobCor database. (To complete this problem successfully, you should know how to use frames and ColdFusion tags. Please...
-
What is the difference between a replacement update and an operator update in MongoDB?
-
Explain what an upsert does.
-
John Adams plans to retire at the age of 62. He wants an annual income of $60,000 per year. John is currently 45 years of age. How much does he have to place at the beginning of each year into a...
-
Assume that four years and one month from today you plan to make the first of several annual withdrawals from an account. Your first withdrawal will equal $1000. You plan for these withdrawals to...
-
If I borrowed 15,000 in student loans at an annual interest of 7%. and then repay $1800 per year, then how long will it take me to repay the loan?
Study smarter with the SolutionInn App