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,...
-
In Internet telephony, explain how a call from Alice can be directed to Bob when he could be either in his office or at home?
-
Let us consider an economy with two risky assets with returns \(\tilde{r}_{1}\) and \(\tilde{r}_{2}\). Show that the explicit formula \(w=\left(\mu-\mathbb{E}\left[\tilde{r}_{2} ight] ight)...
-
A long plastic rod of 30-mm diameter (k = 0.3 W/m K and pc p = 1040kJ/m 3 K) is uniformly heated in an oven as preparation for a pressing operation. For best results, the temperature in the rod...
-
Question 1 Classic Sound is a start-up company that produces vinyl records for numerous record labels worldwide. The company has two full-time employees working in the production department while the...
-
You recently received the following e-mail from a client and friend: Hey Great Student, I cannot believe it is almost year end! Only a few days before its 2019. As you recall, I was lucky enough to...
-
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
-
Borzani Corporation reported net income of $52 million for 2021. Depreciation expense for the year totaled $18 million. Borzani depreciates plant assets over eight years using the straight-line...
-
Suppose the adult population of a city is 9,823,000 and there are 3,340,000 people who are not in the labor force and 6,094,000 who are employed. a. Calculate the number of adults who are in the...
-
Suppose the marginal expense of hiring another worker is $150, and the marginal expense of hiring current workers for an extra hour is $10. The added output associated with an added worker, holding...
-
Assume that the labor supply curve to a firm is the one given in Problem 1. If the firms marginal revenue product (MRP L ) = 240 - 2E, what is the profit-maximizing level of employment (E*), and what...
-
Assume that the war in Iraq increased the desired size of the U.S. military, and assume that potential recruits are reduced by the prospect of facing dangerous, unpleasant wartime conditions. First,...
-
The State of North Carolina has a program for state-subsidized training of disadvantaged workers at its community colleges. Employers adding at least 12 jobs can arrange for a community college to...
-
Discuss five tips for using smartphones courteously, safely, and responsibly.
-
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.
-
f(x)=5x-3, g(x)=x-5 (f+g)(x)=(Simplify your answer.)
-
(5) A small maintenance project consists of the following jobs whose precedence relationships are given below: Job 1-2 1-3 2-3 2-5 3-4 Immediate Predecessor 15 15 3 5 8 8 Activity 3-6 4-5 4-6 5-6 6-7...
-
Let X be a binomial random variable with the probability distribution f(x) shown below. Find the probability distribution of the random variable Y=x. f(x)= Bere 3-x x=0,1,2,3 elsewhere Complete the...
Study smarter with the SolutionInn App