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,...
-
Wilkins, a resident of and licensed by the State of Texas as a certified public accountant (CPA), rendered service in his professional capacity in Louisiana to Coverton Cosmetics Company. He was not...
-
Match each of the following items with its location in the accounting equation. Use the most detailed category appropriate: a. Assets b. Liabilities c. Stockholders' Equity d. Revenues e. Expenses -...
-
Below are incomplete financial statements for Bulldog, Inc. Required: Calculate the missingamounts. BULLDOG, INC. Income Statement BULLDOG, INC. Statement of Stockholders' Equity Common Retained...
-
The 3 year swap price on a new oat swap agreement is $5.94. Interest rates immediately rise on 1, 2, and 3-year zero coupon bonds from 5.1%, 5.4%, and 5.7% to 5.2%, 5.6%, and 6.0%, respectively. What...
-
Raleigh Medical Clinic is considering acquiring 2 new ultrasound machines for $300,000. The clinic estimates that the machines will have an economic life of 4 years after which they will have zero...
-
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
-
1. Write a market-oriented mission statement for Dyson. 2. What are Dyson's goals and objectives? 3. Does Dyson have a business portfolio? Explain. 4. Discuss Dyson's marketing mix techniques and how...
-
A 5 5 . 0 - g object connected to a spring with a force constant of 4 5 . 0 N/m oscillates with an amplitude of 7 . 0 0 cm on a frictionless horizontal surface. (a) Find the total energy of the...
-
Evaluation Title: Environmental Literacy Plan - Phase III FOR AKRON,OH This week you will add to your Environmental Literacy Plan information about climate change and NIMBY in your community. You...
-
1. The atomic number equals the number of a. protons. b. neutrons. c. electrons. d. protons and neutrons. 2. The atomic weight is equal to the sum of a. neutrons. b. protons and neutrons. c. neutrons...
-
4. Protons are a. located in the shells. b. part of the atomic nucleus. c. negatively charged. d. uncharged particles 5. Particles of an atom located in the outermost shell and available for chemical...
-
solve the nonsquare system x - 2 y + 5 z = 2 and 4 x - z = 0
-
What is a virus? How can users and system administrators prevent virus infections?
-
On January 1, 2018, Khalid Ltd., which follows IAS 17, entered into an eight-year lease agreement for three dryers. Annual lease payments for the equipment are $28,500 at the beginning of each lease...
-
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.
-
"You have to decide whether or not to invest in the following 3 projects. The cost of capital is 6%. Project A requires an initial investment of $1,000,000 now. The project will generate cash flows...
-
You bought a bond for $1020 today. The bond's coupon rate is 6.7%, with 12 years left to maturity and a par value of $1,000. What is the yield to maturity of the bond?
-
Mercy, Corp. issued a 8-year bond with a face value of $1,000, a coupon rate of 8.6% and a yield to maturity of 7.9%. What is the current value of the bond?
Study smarter with the SolutionInn App