Write a program to make the UDP server program in Table 25.1 more generic: to receive a
Question:
Write a program to make the UDP server program in Table 25.1 more generic: to receive a request, to process the request, and to send back the response.
Table 25.1
Transcribed Image Text:
Table 25.1 Echo server program using UDP 1 / UDP echo server program 2 #include "headerFiles.h" 3 int main (void) { II Declare and define variables int s; I/ Socket descriptor (reference) // Length of string to be echoed I/ Data buffer int len; 8 char buffer [256]; struct sockaddr_in servAddr; // Server (local) socket address // Client (remote) socket address 10 struct sockaddr_in clntAddr; 11 int clntAddrLen; I/ Length of client socket address I/ Build local (server) socket address memset (&servAddr, 0, sizeof (servAddr)); 12 II Allocate memory 13 // Family field I/ Default port number 14 servAddr.sin_family = AF_INET; 15 servAddr.sin_port = htons (SERVER_PORT) servAddr.sin_addr.s_addr=htonl(INADDR_ANY); I/ Default IP address I/ Create socket if (s = socket (PF_INET, SOCK_DGRAM, 0) < 0); 16 17 18 19 20 perror ("Error: socket failed!"); 21 exit (1); 22 23 I/ Bind socket to local address and port 24 if (bind (s, (struct sockaddr*) &servAddr, sizeof (servAddr) < 0); 25 26 perror ("Error: bind failed!"); 27 exit (1); 28 29 for (; ;) I/ Run forever 30 { I/ Receive String 31 32 len = recvfrom (s, buffer, sizeof (buffer), 0, 33 (struct sockaddr*)&clntAddr, &clntAddrLen); 34 I/ Send String 35 sendto (s, buffer, len, 0, (struct sockaddr*)&clntAddr, sizeof(clntAddr); }// End of for loop 37 } // End of echo server program 36 4799
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 70% (10 reviews)
This is the general UDP server program in the C language in which the server receives an array of ...View the full answer
Answered By
Mamba Dedan
I am a computer scientist specializing in database management, OS, networking, and software development. I have a knack for database work, Operating systems, networking, and programming, I can give you the best solution on this without any hesitation. I have a knack in software development with key skills in UML diagrams, storyboarding, code development, software testing and implementation on several platforms.
4.90+
60+ Reviews
144+ 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 server program in Table 25.3 more generic: to receive a request, to process the request, and to send back the response. Table 25.3 Echo server program using the...
-
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...
-
Write Python code that prompts the user to enter his or her age and assigns the users input to an integer variable named age.
-
Accentrics Limited has the following information available regarding its share capital at December 31, 2016: Preferred shares, $3.50 cumulative, 20,000 shares issued........................$1,000,000...
-
If u = RT ln (aT Vn) find du in terms of dT , dV, and dn, where R and a are constants.
-
The solar constant is defined as the average flux of solar energy incident on the outer fringes of the Earth's atmosphere and a commonly used value is \(1.353 \mathrm{~kW} / \mathrm{m}^{2}\). If the...
-
Suppose a five-year, $1000 bond with annual coupons has a price of $900 and a yield to maturity of 6%. What is the bonds coupon rate?
-
Why was opening trade with China permanently different from other trade agreements? What were its positive and negative impacts on the US?
-
Employees sometimes make mistakes and errors in recording accounting transactions. Is this considered fraud?
-
In Figure 25.10 in the text, how does the server know that a client has requested a service? Figure 25.10 Sockets used in TCP communication Server O Connection establishment Client 1 Data transfer...
-
Assume we add a new protocol to the application layer. What changes do we need to make to other layers?
-
a. Why is the enthalpy change of hydration always exothermic? b. Write equations to represent: i. The hydration of a sodium ion ii. The hydration of a chloride ion. c. Draw diagrams to show: i. 4...
-
What is the international community doing to assist the least-developed countries (such as Niger) with resilience to climate change? Can you identify any limitations to this assistance?
-
Of the light bulbs delivered on May 25, 400 are produced in the morning shift, 300 in the evening shift, and 300 in the night shift. Say we pick a light bulb at random. (a) What is the probability...
-
What is the probability of getting the same outcome in 2 rolls of a die? What is the probability that the sum of 2 outcomes is 7?
-
Draw 2 cards from a deck of cards without replacement. What is the probability of getting a diamond on the first draw and a club on the second? What is the probability of drawing 2 cards and getting...
-
A bag contains three balls: a black one, a white one, and a red one. A magician takes the balls out one by one. Draw an outcome tree. What is the probability of drawing the balls in the order of...
-
During a job interview, do the interviewer and the interviewee want the same thing? How do their purposes differ?
-
A firm has the following balance sheet: Assets Cash Accounts receivable Inventory Plant and equipment $ 15,000 150,000 92,000 170,000 $427,000 Liabilities and Equity Accounts payable Long-term debt...
-
What Oracle function should you use to calculate the number of days between your birthday and the current date?
-
What string function should you use to list the first three characters of a companys EMP_LNAME values? Give an example, using a table named EMPLOYEE.
-
What two things must a SQL programmer understand before beginning to craft a SELECT query?
-
1. What is service-oriented architecture and how is it different from Web services architecture? 2. What is the role of the systems approach in the SDLC? 3. Briefly discuss the key phases of the SDLC...
-
1. Define the role of CRM in your own words. 2. What are the key differences between todays CRM and the early generation of CRMs? 3. How does CRM impact the companys bottom line or performance? 4....
-
What do you think are Thorndike's major contributions to learning theory and teaching? Share a time when you have observed Connectionism. How useful do you think the theory of Connectionism is in an...
Study smarter with the SolutionInn App