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...
-
A countershaft carrying two V-belt pulleys is shown in the figure. Pulley A receives power from a motor through a belt with the belt tensions shown. The power is transmitted through the shaft and...
-
Run confidence intervals by state using the ANES Muslims feeling thermometer and report the 95% confidence intervals for the first five states: Alaska (AK), Alabama (AL), Arkansas (AR), Arizona (AZ),...
-
Theresa Thayer, a friend from college, asks you to form a partnership to import fragrances. Since graduating, Thayer has worked for the Spanish Embassy, developing important contacts among government...
-
A corporate bond has the coupon rate of 8% and the yield to maturity (YTM) of 9%. What can you infer about the current yield of this Bond? Specifically, is it below 8%, between 8% and 9%, or above...
-
Dylan, Devon, and Ricken form Lemon Corporation in the current year. Dylan contributes $30,000 cash in exchange for 30 shares of Lemon. Devon contributes land with a market value of $50,000 (basis of...
-
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...
-
The time between shocks or the ________________interval and the time away from shocks produced by responses or the ________________interval are two aspects of escape and avoidance. (a) temporal...
-
Repeat Prob. 10-18 for signed-magnitude binary numbers. Prob. 10-18 Derive an algorithm in flowchart form for the comparison of two signed binary numbers when negative numbers are in signed-2's...
-
Tideview Home Health Care, Inc., has a bond issue outstanding with eight years remaining to maturity, a coupon rate of 10 percent with interest paid annually, and a par value of $1,000. The current...
-
Captain Billy Whirlywhirl Hamburgers issued 7%, 10-year bonds payable at 70 on December 31, 2010. At December 31, 2012, Captain Billy reported the bonds payable as follows: Captain Billy Whirlywhirl...
-
Two scenarios about the future of the global economy in 2050 have emerged. Known as continued globalization, the first scenario is a (relatively) rosy one. Spearheaded by Goldman Sachs, whose...
-
Visit www.pearsonglobaleditions.com/malhotra to read the video case and view the accompanying video. Nike: Associating Athletes, Performance, and the Brand highlights Nike's use of marketing research...
-
The 2x2 matrix representing a rotation of the xy plane is Show that (except for certain special angleswhat are they?) this matrix has no real eigenvalues. (This reflects the geometrical fact that no...
-
Calculate I, , and a for a 0.0175 m solution of Na 3 PO 4 at 298 K. Assume complete dissociation. How confident are you that your calculated results will agree with experimental results?
-
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...
-
Bought an old van for 4000 from Peters promising to pay laterwhat is the transactions
-
Company has a following trade credit policy 1/10 N45. If you can borrow from a bank at 9,5% annual rate, would it be beneficial to borrow money and pay off invoices earlier?
-
Given the following exchange rates, which of the multiple-choice choices represents a potentially profitable inter-market arbitrage opportunity? 129.87/$1.1226/$0.00864/ 114.96/ B $0.8908/ (C)...
Study smarter with the SolutionInn App