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
42+ 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.
-
In SCTP, a packet is carrying a COOKIE ACK message and a DATA chunk. If the user data is 20 bytes, what is the size of the packet?
-
A vertical plate \(3 \mathrm{~m}\) long is at a temperature of \(400 \mathrm{~K}\) and exposed to air at \(300 \mathrm{~K}\). Calculate the thickness of the boundary layer and the value of the local...
-
International Microcircuits, Inc. Megan Bedding, vice-president of sales for International Microcircuits, Inc. (IM), was delighted when IM was one of the few firms invited to enter a bid to supply a...
-
The Field, Brown & Snow are partners and share income and losses equality. The partner decide to liquidate the partnership when their capital balances are as follows: Field, $131,100; Brown,...
-
Finley Heaters Inc. is a mid sized manufacturer of residential water heaters. Sales have grown during the last several years, and the companys production capacity needs to be increased. The companys...
-
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.
-
What costs are associated with imperfectly anticipated inflation? Discuss them carefully. Who loses, and who gains, when inflation is higher than we expect?
-
Why do upward-sloping labor supply curves to firms cause the marginal expense of labor to exceed the wage rate?
-
In the 1920s, South Africa passed laws that effectively prohibited black Africans from working in jobs that required high degrees of skill; skilled jobs were reserved for whites. Analyze the...
-
When Plant X closed, Employer Y (which offers no training to its workers) hired many of Xs employees after they had completed a lengthy, full-time retraining program offered by a local agency. The...
-
Suppose that the supply curve for optometrists is given by L s = -6 + 0.6W, while the demand curve is given by L D = 50 - W, where W = annual earnings in thousands of dollars per year and L =...
-
A recent magazine article on Japans economic problems stated, As the post-war baby-boomers reach their 50s, Japans lifetime employers are carrying the cost of paying their senior workers more than...
-
Some employment authors claim that the paper resume is dead or dying. What's behind this assertion, and how should current job candidates respond?
-
The MIT Sloan School of Management is one of the leading business schools in the U.S. The following table contains the tuition data for the masters program in the Sloan School of Management. a. Use...
-
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?
-
Write summary of 300 words, with references and 2 question regarding the Feminist Work and Community Education Viv Rogers The concept of community education is subject to similar confusions of...
-
Explain scanning the internal and external environment of the organization.
-
ANSWER ALL QUESTIONS 1. Illustrate and explain with examples the risk-return trade off graph of money market, foreign exchange market, bond market, equity market and derivatives market. State and...
Study smarter with the SolutionInn App