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...
-
Given two arrays each of length n, arr1, and arr2, in one operation, any two elements of an array can be swapped. This can occur any number of times. Find the maximum possible sum of i*(arr2[1]-...
-
Extend the analysis of heat transfer over a wedge flow. Derive the following equation for the temperature profile: \[\begin{equation*}\theta^{\prime \prime}+(m+1) \operatorname{Prf} \theta^{\prime}=0...
-
Refer to the data in the previous problem for Peterson Pipes. Peterson expects its first-quarter opening balances in cash, accounts receivable, and accounts payable to be $75,000, $125,000, and...
-
Larner Corporation is a diversified manufacturer of industrial goods. The company's activity-based costing system contains the following six activity cost pools and activity rates: Activity Cost Pool...
-
You are working on a free-form Packet Tracer challenge activity as seen in Figure 1, you have been given the London Railways network.' The purpose of this EMA question is to build upon each of the...
-
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.
-
Which department authorizes changes in employee pay rates?
-
The concept of compensating wage premiums for dangerous work does not apply to industries like the coal industry, where the union has forced all wages and other compensation items to be the same....
-
The manager of a major league baseball team argues: Even if I thought Player X was washed up, I couldnt get rid of him. Hes in the third year of a four-year, $24-million deal. Our team is in no...
-
Based on the regression estimate in Problem 4, evaluate the statistical significance of the estimated coefficients in the regression. Problem 4 Suppose you have information on which of the 13...
-
Workers in a certain job are trained by the company, and the company calculates that to recoup its investment costs, the workers wages must be $5 per hour below their marginal productivity. Suppose...
-
If anti-sweatshop movements are successful in raising pay and improving working conditions for apparel workers in foreign countries, how will these changes abroad affect labor market outcomes for...
-
Why is it important to include a cover message with all resumes you send, even if you send them by e-mail?
-
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.
-
What is the half-life in hours of procainamide in a patient whose total clearance is estimated to be 20 L/h and the volume of distribution is 120 L assuming one compartment, open model, first- order...
-
1. The technologies, such as ChatGPT, has been launched before introducing even a baseline of safety measures. This goes back to trade-offs that companies make, and people just watch the impact from...
-
The cumulative incidence of myocardial infarction is 180.0 new cases per 10,000 persons among individuals with severe hypertension. In contrast, the cumulative incidence of myocardial infarction is...
Study smarter with the SolutionInn App