Explain how a UDP client program (Table 25.13) sleeps until the response comes from the server. Table
Question:
Explain how a UDP client program (Table 25.13) sleeps until the response comes from the server.
Transcribed Image Text:
Table 25.13 A simple UDP client program 1 import java.net.*; 2 import java.io.*: 3. 4 public class UDPClient 6. final int buffSize = ..; // Add buffer size DatagramSocket sock; String request; 7 8. String response; InetAddress servAddr; 10 11 int servPort; 12 13 UDPClient (DatagramSocket s, String sName, int sPort) 14 throws UnknownHostException 15 16 sock = s; 17 servAddr = InetAddress.getByName (sName); 18 servPort = sPort: 19 20 21 void makeRequest () 22 I/ Code to create the request string to be added here. void sendRequest ) try 29 { 30 byte [] sendBuff = new byte [buffSize]; 31 sendBuff = request.getBytes (0; 32 DatagramPacket sendPacket = new DatagramPacket (sendBuff, 33 sendBuff.length, servAddr, servPort); 34 sock.send(sendPacket); 35 36 catch (SocketException ex) 37 { 38 System.er.println ("SocketException in getRequest"); 39 40 41 42 void getResponse 0 43 { try 45 byte [] recvBuff = new byte [buffSize]; 47 DatagramPacket recvPacket = new DatagramPacket (recvBuff, buffSize); 48 sock.receive (recvPacket): 49 recvBuff = recvPacket.getData (); response = new String (recvBuff, 0, recvBuff.length); 51 catch (SocketException ex) 53 { System.er.println ("SocketException in getRequest"); 58 void useResponse 0 59 60 // Code to use the response string needs to be added here. 61 62 63 void close () 64 65 sock.close (); 66 67 68 public static void main (String [] args) throws IOException, SocketException 69 70 final int servPort ...; I/Add server port number 71 final String servName = ...; IIAdd server name 72 DatagramSocket sock = new DatagramSocket (); 73 UDPClient client = new UDPClient (sock, servName, servPort); 74 client.makeRequest (); client.sendRequest (); client.getResponse (); client.useResponse (): 75 76 77 78 client.close (); }// End of main 80 } // End of UDPClient class 79
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 58% (12 reviews)
The client program executes the clientgetRes...View the full answer
Answered By
Payal Mittal
I specialize in finance and accounts.You can ask any question related to til undergradution.Organizational behaviour and HRM are my favourites for you can always relate to them and is an art with practical knowledge base.
4.90+
226+ Reviews
778+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Write a program to make the UDP client program in Table 25.2 more generic to be able to send any request created by the client program. Table 25.2 Echo client program using UDP I/ UDP echo client...
-
Write a program to make the TCP client program in Table 25.4 more generic to be able to send any request created by the program. Table 25.4 Echo client program using TCP 1 / TCP echo client program 2...
-
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...
-
For problems involving composite bodies composed of two or more materials, the elasticity solution requires both boundary conditions and interface conditions between each material system. The...
-
The accountant for Ellery Co., a private company reporting under ASPE, recorded the following journal entries: 1. A building with a cost of $75,000 is reported at its fair value. The following entry...
-
The point at which a companys profits equal zero is called the companys break-even point. For problem, let R represent a companys revenue, let C represent the companys costs, and let x represent the...
-
Antibiotics in Infancy and Obesity in Adults "Antibiotics in infancy may cause obesity in adults," claims a recent headline. A study in mice randomly assigned infant mice to either be given...
-
This problem takes you through the accounting for sales, receivables, and uncollectibles for Dependable Delivery Corp, the overnight shipper. By selling on credit, the company cannot expect to...
-
A . Prepare an income statement for the year ended dec . 3 1 2 0 2 3 B . Prepare a retianed earnings statement for the year ended dec. 3 1 2 0 2 3 C . Prepare the stock holders equity section of the...
-
A mixture of three amino aids is separated by gel electrophoresis. The three amino acids are glycine, valine and phenylalanine (Figure 27.14). a. The electrophoresis is carried out in a buffer...
-
How is a Socket object in a TCP client (Figure 25.18) created and destroyed? Figure 25.18 Figure 25.18 Design of the TCP client Client application program Create request Use response | String String...
-
In Figure 25.15, assume that the request is a URL to retrieve a picture. How is the URL stored in the recvBuff? Figure 25.15 Figure 25.15 Design of the UDP server Server application program Process...
-
Goltra Company is considering purchasing equipment. The equipment will produce the following cash inflows: Year 1, $30,000; Year 2, $40,000; Year 3, $50,000. Goltra requires a minimum rate of return...
-
Assume the following utility function U = (q M)/100. Importantly, q represents the fish population (numbers), and M represents income (tens of thousands of yen, M = 100). a. State the WTP amount...
-
Investigate issues with implementing domestic biodiversity offsetting.
-
What are the benefits and drawbacks of direct regulations?
-
Describe the impact that one countrys environmental policies could have on another countrys trade.
-
Winter Games manufactures a competitive line of skis and sells its skis to retailers at a price of $225 per pair. Based on an annual volume of 5,000 pairs, the cost per pair is $185: Sports Palace, a...
-
What channels are used for routine messages in organizations today?
-
How do network effects help Facebook fend off smaller social-networking rivals? Could an online retailer doing half as much business compete on an equal footing with Amazon in terms of costs? Explain.
-
Which of the following is a valid datatype? a. CHAR3 b. VARCHAR4(3) c. NUM d. NUMBER
-
Which object in the data dictionary enables you to verify DEFAULT column settings? a. DEFAULT_COLUMNS b. DEF_TAB_COLUMNS c. USER_TAB_COLUMNS d. None of the above
-
Which of the following SQL statements changes the size of the Title column in the BOOKS table from the current length of 30 characters to the length of 35 characters? a. ALTER TABLE books CHANGE...
-
Hinrich Company traded machinery with a book value of $120,000 and a fair value of $200,000. It received in exchange from Noach Company a machine with a fair value of $180,000 and cash of $20,000....
-
You have just moved from Norfolk, Virginia (sea level), to Taos, New Mexico (high in the mountains), and you find yourself out of breath climbing a small hill. Three months later, climbing the same...
-
Starline is a small children's clothing manufacturer and retailer that has seen rapid growth in the last twelve months and a significant increase in employees. At a meeting of managers, a number of...
Study smarter with the SolutionInn App