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+
67+ Reviews
156+ 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...
-
Consider the following dice game: A pair of dice is rolled. If the sum is 7, then the game ends and you win 0. If the sum is not 7, then you have the option of either stopping the game and receiving...
-
We can estimate future crop yields using the exponential growth formula \[ \begin{equation*} \text { Yield }(t)=\text { Yield }_{0} e^{k t} \tag{4.36} \end{equation*} \] where \(k\) is the growth...
-
Gorham Manufacturings sales slumped badly in 2010. For the first time in its history, it operated at a loss. The companys income statement showed the following results from selling 600,000 units of...
-
Provide a detailed explanation explaining the importance of organizational politics in the workplace. I am providing two references that you can use in your response. Please provide the pros and cons...
-
The following cross tabulation shows the average speed of the 25 winners by year of the Daytona 500 automobile race (The 2013 World Almanac). a. Calculate the row percentages. b. W hat is the...
-
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?
-
What amount, seven months from now, is equivalent to $1215 today if money can be invested to earn 8 %
-
a. Find the present values of the following cash flow streams at an 8% discount rate. Do not round intermediate calculations. Round your answers to the nearest cent 0 I 2 3 4 5 Stream A $0 $100 $450...
-
Shady Inc. manufactures outdoor umbrellas. The company has the capacity to produce 100,000 units per year, but it currently produces and sells 75,000 units per year. The following information relates...
-
1. Smith Corp. stock had the following information: Price as of 12/31/19 $75 per share Price as of 12/31/18 $87 per share Dividend received during the year $2,50 What is the stock's total return for...
-
Doran Technologies produces a single product. Expected manufacturing costs are as follows: Variable costs Direct materials $4.00 per unit Direct labor $1.20 per unit Manufacturing overhead $0.95 per...
-
1. What is the payback period for a project with the following cash flows? Cash flows 0 1234 (12,300) 2,300 5,450 2,750 2,600
-
Find the endpoints of the t-distribution with 2.5% beyond them in each tail if the samples have sizes n 1 = 15 and n 2 = 25. Assume the samples are random samples from distributions that are...
-
The following cost information was provided to you for analysis: September 12,000 Units Produced Costs: TIC TAC TOE TING August 10,000 P80,000 70.000 60.000 50,000 How much is the fixed cost per...
-
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?
-
(a) What is the kinetic energy in joules of a 1140-kg automobile traveling at 93 km/h? (b) How much work would have to be done to bring a 1140-kg automobile traveling at 93 km/h to a stop? 4. How...
-
A charging RC circuit controls the intermittent windshield wipers in a car. The emf is 12.0 V. The wipers are triggered when the voltage across the 120F capacitor reaches 12.0 V; then the capacitor...
-
A block of mass 2 kg is attached to a spring with a spring constant of 100 N/m. The block is released from rest and moves along a rough horizontal surface with a coefficient of friction of 0.2. How...
Study smarter with the SolutionInn App