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+
70+ Reviews
162+ 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...
-
Alabama law imposes a fee of $97.60 per ton for hazardous wastes generated outside the state and disposed of at a commercial facility in Alabama. The fee for hazardous wastes generated within Alabama...
-
Connor Health Foods has 10,000 shares of \(\$ 1\) par common stock outstanding, which was issued at \(\$ 10\) per share. Connor also has retained earnings of \(\$ 80,000\). How much is Connor's total...
-
A bank manager of City savings bank Inc. uses the managerial accounting system to track the costs of operating the various departments with in the bank. The departments include Cash Management,...
-
Consider the following compound interest scheme, which we'll refer to as Scheme RST throughout this test. Scheme RST An interest rate of r > 0 is applied at the end of the first week, An interest...
-
A hollow, circular, cast-iron pipe (Ec = 12,000 ksi) supports a brass rod (Eb 14,000 ksi) and weight W = 2 kips, as shown. The outside diameter of the pipe is dc = 6 in. (a) If the allowable...
-
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?
-
The off-gas from a reactor in a process plant in the heart of Freedonia has been condensing and plugging up the vent line, causing a dangerous pressure buildup in the reactor. Plans have been made to...
-
1) In the functional finance finance view, bond sales: Finance deficit spending Add to bank reserves depleted by deficit spending Drain excess reserves to maintain short term interest rates None of...
-
Provide responses to the "QUESTIONS" presented for each of the following cases from this week's reading assignment: Guidelines Upload one document that includes all responses Content is worth 70%...
-
Writeajavaprogramtoprintbelow pattern? CCC C DDDD
-
Kevin Whalling, Chief Counsel for the Whalling Law Group, PLLC, has been hired to act as defense counsel for Mr. Bill Carson. Mr. Carson was arrested recently by the Phoenix Police Department for...
-
How can organizations establish mechanisms for constructive conflict resolution and negotiation to manage power dynamics effectively and promote organizational harmony ?
-
List the FMS layers and describe their functions.
-
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?
-
18. During your years as a wise college freshman you racked up $3,478 in credit card debt. The card's APR is 17.99%, and you plan to pay off the card with reasonable monthly payments of $150 per...
-
is discussion activity features a dream vacation of your choice and associated annuity calculations. Tell us about your dream vacation. Do some quick research to find out how much this dream vacation...
-
Based on the brief transcript/ scenario below and the cuts that are being proposed, what would be the best solution in creating an operating budget for the department? Do you take a 'salami slice'...
Study smarter with the SolutionInn App