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: 85% (14 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...
-
The following data relate to the operation of Kramer Co.s pension plan in 2021. The pension worksheet for 2020 is provided in P20.10. Service...
-
Structure Petroleum began in 2015 with the acquisition of four individually significant unproved leases. Give the entries, assuming the following transactions. You may combine entries for items...
-
Variance analysis, working backward. The Jinwa Corporation sells two brands of wine glasses: Plain and Chic. Jinwa provides the following information for sales in the month of June 2011:...
-
If you already know lal and [v], then the formula a =lv gives a convenient way to find the curvature. Use it to find the curvature and radius of curvature of the curve r(t)=(cost+t sin t) i+ (sin t-t...
-
In light of the successful turnaround do you think the federal bailout of GM was warranted What are the pros and cons after the fact Which factors that were pivotal to the sales rebound at GM were...
-
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.
-
Explain the no-fault ground of marital breakdown.
-
What is the significance of the lack of privileged communication between an auditor and his or her client?
-
Which of the following is not an example of an error? a. Entity personnel make mistakes in gathering or processing accounting data from which financial statements are prepared. b. Entity personnel...
-
In a belt transmission dynamometer, the distance between the centre of driving pulley and dead weights is \(1 \mathrm{~m}\). Find the value of dead weights required to keep the lever in horizontal...
-
Describe the four types of audit opinions.
-
Why would studying and evaluating each of the client's controls not necessarily be the most efficient way of determining the scope of related substantive tests?
-
Evaluate the indefinite integral. cosh x dx | sinhx
-
Answer the following two independent questions. a. MM Corporation is considering several proposed investments for the coming budget year. MM produces electrical apparatus for industrial complexes....
-
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.
-
Accounting I15) SO ICEY Inc. has a periodic inventory system. The company purchased 225 units ofinventory at $11.50 per unit and 350 units at $12.50 per unit. What is the weightedaverage unit cost...
-
6-9Unearned Income of Minor Children and Certain Students (LO 6.4)Explain the two different ways that the tax on unearned income of minor children, or "kiddie tax," can be reported.The "kiddie tax"...
-
To evaluate a company's earning potential, a buyer should review past income statement and balance sheet items. Sales tax records, income tax returns and financial statements are valuable sources of...
Study smarter with the SolutionInn App