Write a program to make the UDP client program in Table 25.2 more generic to be able
Question:
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.
Transcribed Image Text:
Table 25.2 Echo client program using UDP I/ UDP echo client program #include "headerFiles.h" int main (int arge, char* argv[ ]) // Three arguments to be checked later // Declare and define variables int s; I/ Socket descriptor 6. // Length of string to be echoed // Server name int len; char* servName; I/ Server port // String to be echoed // Data buffer // Server socket address int servPort; char* string; char buffer [256 + 1]; 10 12 struct sockaddr_in servAddr; I/ Check and set program arguments if (argc != 3) 13 14 15 16 printf ("Error: three arguments are needed!"); exit(1): servName=argv[1]; servPort = atoi (argv[2]); string = argv[3]; // Build server socket address memset (&servVAddr, 0, sizeof (servAddr)): servAddr.sin_family = AF_INET; inet_pton (AF_INET, servName, &servAddr.sin addr); servAddr.sin port = htons (servPort): // Create socket if ((s = socket (PF_INET, SOCK_DGRAM, 0) < 0); perror ("Error: Socket failed!"): exit (1); I/ Send echo string len = sendto (s, string, strlen (string), 0, (struct sockaddr)&servAddr, sizeof (servAddr)); I/ Receive echo string recvfrom (s, buffer, len, 0, NULL, NULL); // Print and verify echoed string 38 buffer [len] = "0'; printf ("Echo string received: "; fputs (buffer, stdout); I/ Close the socket 40 41 close (s);s 43 // Stop the program 44 exit (0): 45 J// End of echo client program
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 63% (11 reviews)
This is the general UDP client program in the C langu...View the full answer
Answered By
Jeff Omollo
As an educator I have had the opportunity to work with students of all ages and backgrounds. Throughout my career, I have developed a teaching style that encourages student engagement and promotes active learning. My education and tutoring skills has enabled me to empower students to become lifelong learners.
5.00+
5+ Reviews
46+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
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 Table 25.1 Echo server program using...
-
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...
-
Which of the following is indeterminate at x = 1? x + 1 x-1' 2-1 x + 2 x - 1 x+3-2' x + 1 x+3-2
-
Shareholders' equity on the balance sheet is divided into major components. Identify and explain what each component represents.
-
Sweeten Company had no jobs in progress at the beginning of the year and no beginning inventories. It started, completed, and sold only two jobs during the year Job P and Job Q . The company uses a...
-
Benjamin Franklin (1706-1790) conducted an experiment to study the effect of water depth on the amount of drag on a boat being pulled up a canal. He made a 14-foot trough and a model boat 6 inches...
-
The following transactions, adjusting entries, and closing entries were completed by Yellowstone Furniture Co. during a 3-year period. All are related to the use of delivery equipment. The...
-
The following events occurred for Johnson Company: a. Received investment of cash by organizers and distributed to them 1,010 shares of $1 par value common stock with a market price of $40 per share....
-
A Y-connected load, with Z A = 10 0 , Z B = 10 60, and Z C = 10 60 , is connected to a three-phase, three-wire, ABC system having effective line voltage 141.4 V. Find the load voltages V AO , V BO...
-
In Figure 25.12 in the text, how is the socket created for data transfer at the server site? Figure 25.12 Figure 25.12 Socket data structure Length Family Port number IP address Family Type Protocol...
-
Explain which entity provides service and which one receives service in the client-server paradigm.
-
Determine the magnitude of the resultant force and its direction, measured counterclockwise from the positive x axis. y F1 = 200 N 45 30 F = 150 N
-
A painter leans a ladder at some angle against a smooth wall, with the foot of the ladder resting on wall-to-wall carpeting. Why might the ladder slip as he climbs it?
-
Arbitration in the Malpractice Arena Recently, a group of New Jersey gynecologists have come under fire for requiring their patients to sign a binding arbitration agreement before treating them. The...
-
Two balls of the same radius and same inertia roll down an inclined plane, starting from rest. One ball is hollow, and the other is solid. What is the ratio of the time intervals the two balls...
-
What are a reasonable down payment and monthly payment for a home in your area?
-
An object rolls without slipping onto a surface where the coefficient of friction between object and surface is twice as great as that needed to prevent slipping. Describe the subsequent motion.
-
In a hydroelectric dam, water falls 25 m and then spins a turbine to generate electricity. a. What is U G of 1.0 kg of water? b. Suppose the dam is 80% efficient at converting the waters potential...
-
Tanaka Company's cost and production data for two recent months included the following: March April Production (units).........300................600 Rent.....................$1,800............$1,800...
-
What is polyglot persistence, and why is it considered a new approach?
-
What are the key assumptions made by the Hadoop Distributed File System approach?
-
What is the difference between a name node and a data node in HDFS?
-
You are a supervisor at your company. You've overheard Employee A making offensive comments to other employees, and Employee B has complained about these comments. You've given Employee A a verbal...
-
What is the probability of developing and dying from cancer today?
-
On January 1, 2024, Majestic Mantles leased a lathe from Equipment Leasing under a finance lease. Lease payments are made annually. Title does not transfer to the lessee and there is no purchase...
Study smarter with the SolutionInn App