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...
-
Do you consider yourself handicapped in any way?
-
Why may an auditor decide not to rely on a prescribed procedure?
-
Otis Thorpe Corporation has 10,000 shares of $100 par value, 8%, preferred stock and 50,000 shares of $10 par value common stock outstanding at December 31, 2008. Instructions Answer the questions in...
-
During the year, the Senbet Discount Tire Company had grosssales of $1.22 million. The company\'s cost of goods sold andselling expenses were $541,000 and $231,000, respectively. Thecompany also had...
-
Mary Janes Beauty Shop has recently invested money to add more equipment to enable more services to be offered at the shop. Given the following information evaluate their investment.
-
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...
-
What is the monetary base? How does the Federal Reserve influence its size?
-
In the program below, after the declaration of the string text, what does text[4] contain (expressed as a character rather than as a number)? int main() { } char text[] = "lion";
-
What gets printed? #include int main() { } char text [4]; text [0] = 's'; text [1] = 'u'; text [2] = 'n'; text [3] = '\0'; printf("%s", text);
-
One of the forecasters below is making a bad decision which could lower the quality of the revenue baseline they forecast. Which one is it? A. Jamiya Forecaster decides to consult appropriate...
-
Bims Corporation uses the weighted-average method in its process costing system. The Assembly Department started the month with 6,000 units in its beginning work in process inventory that were 90%...
-
Suppose that instead of having a sample of 10 batteries you have 20 batteries. Construct a 95% confidence interval, and contrast this interval to the interval found in question 1. What happens to the...
-
Test H 0 : = 10 vs H a : > 10 using the sample results x = 13.2, s = 8.7, with n = 12. Use the t-distribution and the sample results to complete the test of the hypotheses. Use a 5% significance...
-
Which of the ocean zones shown would be home to each of the following organisms: lobster, coral, mussel, porpoise, and dragonfish? For those organisms you identify as living in the pelagic...
-
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...
-
Fields Company has two manufacturing departments, forming and painting. The company uses the weighted method and it reports the following unit data for the Forming department. Units completed in the...
-
Discuss and describe a specific process for creating artwork that involved procedures for combining diverse materials; describe in detail the selected product you posted. Part II Discuss and cite an...
-
What mechanisms do cells use to regulate vesicle trafficking within the endomembrane system, and how do SNARE proteins contribute to vesicle fusion ?
Study smarter with the SolutionInn App