Write a program to make the TCP server program in Table 25.3 more generic: to receive a
Question:
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.
Transcribed Image Text:
Table 25.3 Echo server program using the services of TCP 1 / Echo server program 2 #include "headerFiles.h" int main (void) // Declare and define 6. int Is; I/ Listen socket descriptor 7 int s; Il Socket descriptor (reference) 8 char buffer [256]: I/ Data buffer 9. char* ptr = buffer; I/ Data buffer 10 int len = 0; I/ Number of bytes to send or receive I/ Maximum number of bytes // Number of bytes for each recv call I/ Size of waiting clients I/ Server address // Client address 11 int maxLen = sizeof (buffer); 12 int n = 0; 13 int waitSize = 16; 14 struct sockaddr_in serverAddr; 15 struct sockaddr in clientAddr; 16 int clntAddrLen; // Length of client address 17 // Create local (server) socket address 18 memset (&servAddr, 0, sizeof (servAddr); 19 servAddr.sin_family = AF_INET; 20 servAddr.sin_addr.s_addr = htonl (INADDR_ANY); I/ Default IP address 21 servAddr.sin_port = htons (SERV_PORT); // Default port // Create listen socket if (Is = socket (PF_INET, SOCK_STREAM, 0) < 0); 23 perror ("Error: Listen socket failed!"); exit (1); 28 // Bind listen socket to the local socket address if (bind (Is, &servAddr, sizeof (servAddr)) < 0); 30 31 perror ("Error: binding failed!"); 32 exit (1); 33 34 // Listen to connection requests 35 if (listen (Is, waitSize) < 0); 36 37 perror ("Error: listening failed!"); 38 exit (1); 39 40 // Handle the connection 41 for (;:) // Run forever 42 // Accept connections from client if (s = accept (Is, &clntAddr, &clntAddrlen) <0): 43 44 45 46 perror ("Error: accepting failed!); 47 exit (1); 48 // Data transfer section while (n = recv (s, ptr, maxLen, 0)) > 0) 49 50 51 52 // Move pointer along the buffer I/ Adjust maximum number of bytes to receive // Update number of bytes received ptr + = n; 53 maxLen - = n; 54 len += n; 56 send (s, buffer, len, 0); // Send back (echo) all bytes received // Close the socket 58 close (s); } // End of for loop 60 1// End of echo server program 59
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 84% (13 reviews)
We have used same strategy as in Prg21 here with some changes Since TCP is a ...View the full answer
Answered By
JAPHETH KOGEI
Hi there. I'm here to assist you to score the highest marks on your assignments and homework. My areas of specialisation are:
Auditing, Financial Accounting, Macroeconomics, Monetary-economics, Business-administration, Advanced-accounting, Corporate Finance, Professional-accounting-ethics, Corporate governance, Financial-risk-analysis, Financial-budgeting, Corporate-social-responsibility, Statistics, Business management, logic, Critical thinking,
So, I look forward to helping you solve your academic problem.
I enjoy teaching and tutoring university and high school students. During my free time, I also read books on motivation, leadership, comedy, emotional intelligence, critical thinking, nature, human nature, innovation, persuasion, performance, negotiations, goals, power, time management, wealth, debates, sales, and finance. Additionally, I am a panellist on an FM radio program on Sunday mornings where we discuss current affairs.
I travel three times a year either to the USA, Europe and around Africa.
As a university student in the USA, I enjoyed interacting with people from different cultures and ethnic groups. Together with friends, we travelled widely in the USA and in Europe (UK, France, Denmark, Germany, Turkey, etc).
So, I look forward to tutoring you. I believe that it will be exciting to meet them.
3.00+
2+ Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
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 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 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...
-
A 300-cm-long piece of straight wire is aligned vertically along the z-axis. The wire carries a downward current of 6.00 A. There is a 2.00-T magnetic field in the negative x-direction surrounding...
-
Corus Entertainment is a media company that delivers interactive television and radio shows. It was founded by J. R. Shaw and built from the media assets originally owned by Shaw Communications. It...
-
A pint of water weighs 1.04 pounds, so 1 pound of water is 0.96 pint. Suppose a merchant sells water in containers weighing 0.5 pound, but customers can fill them to their liking. It is easier to...
-
A rooftop solar hot water heater with collector areas of \(8 \mathrm{~m}^{2}\) and storage of \(640 \mathrm{~L}\) is installed in Phoenix, Arizona, on a house that uses \(160 \mathrm{~L} /\) day of...
-
An excerpt from the Sun Company's annual report is presented below. Calculating any profit measures deemed necessary, discuss the implications of the profitability of thecompany. Sun Company Income...
-
Monty Corp. Inc. had a beginning inventory of 100 units of Product RST at a cost of $9 per unit. During the year, purchases were: Feb. 20 585 units at $10 Aug. 12 395 units at $12 May 5 480 units at...
-
In this assignment you will be required to complete tasks related to job costing. Download the document, complete the required information, save the document, and submit the assignment in Blackboard....
-
Assume we want to make the TCP client program in Table 25.2 more generic to be able to send a string and to handle the response received from the server. Show how this can be done. Table 25.2 Echo...
-
In the client-server paradigm, explain why a server should be run all the time, but a client can be run when it is needed.
-
Evaluate the indefinite integral. dt cost1 + tan t
-
Roush and Sita are age 65 and 67 respectively. Sita's health is rapidly deteriorating and will need to move to an Age Care Facility within the next 6-12 months. Sita has early onset dementia and...
-
Stock A has a risk premium of 8.67 percent. If Treasury bills yield 2.3 percent, the required rate of return is 10.97 percent and the beta coefficient is 1.7. What is the market return?
-
Gilligan just turned 18 and is about to start college at DePaul. His parents started saving for his college three years ago, on his 15th birthday. They put $6,000 into his college account on his 15th...
-
The following data were taken from the financial statements of Loveseth Inc. for the current fiscal year. Property, plant, and equipment (net) $877,800 Liabilities: Current liabilities ...
-
Johnson Controls has a required return on common stock (Ke) of 20 percent. The firm has a constant growth rate (g) of 8 percent. The company will pay a dividend of $7.20 at the end of the year (D1)....
-
The dataset StudentSurvey has information from males and females on the number of hours spent watching television in a typical week. Computer output of descriptive statistics for the number of hours...
-
Velshi Printers has contracts to complete weekly supplements required by fortysix customers. For the year 2018, manufacturing overhead cost estimates total $600,000 for an annual production capacity...
-
Explain why graph databases tend to struggle with scaling out?
-
Explain what it means for a database to be aggregate aware.
-
Using a single sentence, explain the role of databases in organizations. Then explain your answer.
-
How is decision-making in organizations best supported by Management Accounting (a descriptive nature) and how should it be supported by Management Accounting (a prescriptive nature)? Is there a gap...
-
Discuss the thermodynamic principles governing the separation of azeotropic mixtures using advanced distillation techniques such as pressure swing distillation, extractive distillation, and hybrid...
-
respond to the discussion In the IMA article, Activity-Based Costing (ABC) is explained as a cost allocation technique that traces indirect costs (often referred to as "overhead") to specific cost...
Study smarter with the SolutionInn App