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...
-
Helvey brought suit against the Wabash County REMC (REMC) for breach of implied and express warranties. He alleged that REMC furnished electricity in excess of 135 volts to Helveys home, damaging his...
-
The balance sheet data for Bobs Electronics, Co., November 30, 2010, follow: Requirement 1. The following are three independent assumptions about the business during November. For each assumption,...
-
Please discuss the video "Fog of War" and proportionality in war. What was McNamara saying about proportionality during World War II? How do you think this impacted the decision making processes...
-
The banks play a central role in financial intermediation in New Zealand. 1.What is financial intermediation? Who performs it? and why is it important? 2.What is Qualitative Asset transformation...
-
The purpose of this assignment is to develop practical skills in using WHOIS for domain information gathering, an essential aspect of cybersecurity investigations. Students will identify and analyze...
-
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.
-
In Exercises find the derivative of the algebraic function. x + 3 4 I x = (x) f
-
The following data is provided for Garcon Company and Pepper Company for the year ended December 31. Garcon Company Pepper Company Finished goods inventory, beginning $ 12,200 $ 16,450 Work in...
-
the structure of a microring resonator. Light propagating in the waveguide couples with the light in the microring resonator through a coupler (red shaded area). The coupler can be modeled as a beam...
-
Asking if this countermeasure will create more problems than it will solve and what effects will this countermeasure have on my job, team, other operations, and the Air Force describes which of the...
-
6. The tool of choice to observe living microorganisms is the a. bright-field microscope. b. phase-contrast microscope. c. fluorescence microscope. d. electron microscope. 7. Which scientist is most...
-
1. A high school athlete runs 1.00 x 102 m in 12.20 s. What is the velocity in m/s and km/h? 2. A person walks. 13 km in 2.0 h. What is the person's average velocity in km/h and m/s? 5. Suppose a car...
-
Describe the components of the Java EE architecture. What standards govern the form of the client and Web/business tiers? What standards govern communication between components? Is Java EE compatible...
-
Rosalie owns 50% of the outstanding stock of Salmon Corporation. In a qualifying stock redemption, Salmon distributes $80,000 to Rosalie in exchange for one-half of her shares, which have a basis of...
-
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.
-
At January 1, 2024, M. E. Gainor Corporation had outstanding the following securities: 600 million common shares 20 million 6% cumulative preferred shares, $50 par 6.4% convertible bonds, $2,000...
-
market rate of interest. Interest is payable annually on December 31, Carr Corporation issued $45,000 of 5 percent, 9-year bonds on January 1, Year 1, for a price that reflected a 6 percent Note: Use...
-
Italian Stallion has the following transactions during the year related to stockholders' equity. February 1 Issues 5,400 shares of no-par common stock for $16 per share. May 15 Issues 600 shares of...
Study smarter with the SolutionInn App