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...
-
Fox, Dodge, and Gilbey agreed to become limited partners in Palatine Ventures, a limited partnership. In a signed writing each agreed to contribute $20,000. Foxs contribution consisted entirely of...
-
What do closing entries accomplish? a. Transfer revenues, expenses, and dividends to retained earnings b. Zero out the revenues, expenses, and dividends to prepare them for the next period C. Bring...
-
A vertical electric field of magnitude 2.00 x 104 N/C exists above the Earths surface on a day when a thunderstorm is brewing. A car with a rectangular size of 6.00 m by 3.00 m is traveling along a...
-
Advertisers can mislead through exaggeration by making claims unsupported by evidence. Puffery is the supposedly harmless use of superlatives and subjective praise in advertisements. Give an example...
-
Alice has invented a new card game to play with Bob. Alice made a deck of cards with random values between 1 and 52. Bob picks 5 cards. Then, he has to rearrange the cards so that by utilizing the...
-
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...
-
In Exercises find the derivative. y = et + 1 et - 1
-
MCO Leather manufactures leather purses. Each purse requires 2 pounds of direct materials at a cost of $5 per pound and 0.7 direct labor hour at a rate of $13 per hour. Variable overhead is budgeted...
-
Provide a brief description of each term and any historic information about their origins. Then, cover "The legend of Dragoon" and describe how those musical elements listed below are used in that...
-
Provide the missing information. The function f := {(1, 5), (-2, 3), (-4, 2), (2, 5)} (is/is not) a one-to-one function. Please respond only with: is OR is not Answer:
-
On November 1 , 1 9 9 9 Senn Company contracted Super Contractors to have a building constructed for Sh 1 , 7 5 0 , 0 0 0 . Senn made payments for the construction as follows: January 1 , sh 3 1 0 ,...
-
1. What do you think the next Media Industry will be? 2. Why is your idea a valid predictor of where this field is going? What evidence can you find to support your argument? 3. At least 3-4 written...
-
Compare/contrast aggregation with composition for a whole part relationship.
-
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...
-
Last Chance Mine ( LC ) purchased a coal deposit for $ 7 2 0 , 0 0 0 . It estimated it would extract 1 2 , 0 0 0 tons of coal from the deposit. LC mined the coal and sold it reporting gross receipts...
-
BDB Company manufactures its one product by a process that requires two departments. The production starts in Department A and is completed in Department B. Direct materials are added at the...
-
During 2025, Pharoah Company started a construction job with a contract price of $1,620,000. The job was completed in 2027. The following information is available. 2025 2026 2027 Costs incurred to...
Study smarter with the SolutionInn App