Write a program to make the TCP client program in Table 25.4 more generic to be able
Question:
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.
Transcribed Image Text:
Table 25.4 Echo client program using TCP 1 / TCP echo client program 2 #include "headerFiles.h" 3 int main (int argc, char* argv[ ]) // Three arguments to be checked later 4 { I/ Declare and define // Socket descriptor // Number of bytes in each recv call 6. int s; 7 int n; char* servName; I/ Server name I/ Server port number I/ String to be echoed 9 int servPort; 10 char* string; 11 int len; // Length of string to be echoed I/ Buffer // Pointer to move along the buffer I/ Server socket address 12 char buffer [256 + 1]: 13 char* ptr = buffer; 14 struct sockaddr_in serverAddr; // Check and set arguments 15 16 if (arge !- 3) 17 18 printf ("Error: three arguments are needed!"); 19 exit (1); 20 21 servName = arg[1]: 22 servPort = atoi (arg [2]); 23 string = arg [3]; 24 // Create remote (server) socket address 25 memset (&servAddr, 0, sizeof(servAddr); serverAddr.sin family = AF INET; inet_pton (AF_INET, servName, &serverAddr.sin addr); / Server IP address 26 27 28 // Server port number serverAddr.sin_port = htons (servPort); // Create socket 29 30 if ((s = socket (PF_INET, SOCK_STREAM, 0) < 0); 31 32 perror ("Error: socket creation failed!"); 33 exit (1); 34 35 // Connect to the server 36 if (connect (sd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0): 37 38 perror ("Error: connection failed!"); 39 exit (1); 40 41 // Data transfer section 42 send (s, string, strlen(string), 0); 43 while (n = recv (s, ptr, maxLen, 0)) > 0) 44 // Move pointer along the buffer Il Adjust the maximum number of bytes I/ Update the length of string received 45 ptr + = n; 46 maxLen - = n; 47 len += n; 48 J// End of while loop 49 I/ Print and verify the echoed string 50 buffer [len] = '\0'; 51 printf ("Echoed string received: "); fputs (buffer, stdout); I/ Close socket 52 53 54 close (s); 55 Il Stop program 56 exit (0); 57 }// End of echo client program
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (14 reviews)
We have used same strategy as in Prg22 here with some changes Creating the sending data is ...View the full answer
Answered By
Susan Juma
I'm available and reachable 24/7. I have high experience in helping students with their assignments, proposals, and dissertations. Most importantly, I'm a professional accountant and I can handle all kinds of accounting and finance problems.
4.40+
15+ Reviews
45+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
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 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 small piece of zinc is dissolved in 50.00 mL of 1.035M HCl. At the conclusion of the reaction, the concentration of the 50.00 mL sample is redetermined and found to be 0.812 M HCl. What must have...
-
At April 30, partners' capital balances in HIJ Partners are Ho $174,000, Ishikawa $142,000, and Jay $84,000. The income-sharing ratio is 4:2:1, respectively. On May 1, HIJK Partners is formed by...
-
The headline in an article in the Sacramento Bee read Firing someone? Risk of heart attack doubles (Haney, 1998). The article explained that between 1989 and 1994, doctors interviewed 791 working...
-
Calculate the annual payments for a solar system whose initial extra cost is \(\$ 10,000\). Assume that the interest rate is \(8 \%\) and the mortgage term is 15 years.
-
Partial operating data for Census Company follow. Management has set the predetermined overhead rate for the current year at 125 percent of direct labor costs. Using T accounts, compute the unknown...
-
Please help me with a flow chart with the following Scenario: As the lab manager, you have hired a new employee. Your job is to make sure this new employee completes the orientation process, which...
-
Pacifico Company, a U.S.-based importer of beer and wine, purchased 1,500 cases of Oktoberfest-style beer from a German supplier for 390,000 euros. Relevant U.S. dollar exchange rates for the euro...
-
Write a method in Java to accept a string representing an IP address in the form x.y.z.t and change it to an unsigned integer.
-
Can a program written to use the services of UDP be run on a computer that has installed TCP as the only transport-layer protocol? Explain.
-
Rich Mordica is confused about computing physical units. Explain to Rich how physical units to be accounted for and physical units accounted for are determined.
-
Is online banking safe? How will you protect online banking information?
-
Five hundred sixty customers were randomly selected and asked if they use online banking. Results indicated that 140 customers used online banking in the last month. Find a 95.76% confidence interval...
-
Does the EFAA apply only to online banking activities? Was it's passage motivated by the desire to provide needed protection to online banking activities or is it the case that online banking...
-
The purpose of this assignment is to enhance learners' ability to discuss the widespread use of information technology in the banking industry. REQUIREMENT: The advancement of technology within the...
-
As of December 31 of the current year, Armani Company's records show the following. Hint. The owner invested $1,100 cash during the year. Cash Accounts receivable Supplies Equipment Accounts payable...
-
Test H 0 : 1 = 2 vs H a : 1 > 2 using the sample results x 1 = 56, s 1 = 8.2 with n 1 = 30 and x 2 = 51, s 2 = 6.9 with n 2 = 40. Use the t-distribution and the given sample results to complete...
-
Huntingdon Capital Corp. is a competitor of Plazacorp and First Capital Realty. Huntingdon reported the following selected information (in millions):...
-
Write the connectivity and cardinality for each of the entities shown in Question 4. Data from Question 4: What business rule(s) and relationships can be described for the ERD in Figure QB.4? Figure...
-
What is a module, and what role does a module play within the system?
-
What is a module interface, and what does it accomplish?
-
Warnerwoods Company uses a perpetual inventory system. It entered into the following purchases and sales transactions for March. Submit Date March 1 March 5 March 9 March 18 March 25 March 29...
-
Wilmington Company has two manufacturing departments-Assembly and Fabrication. It considers all of its manufacturing overhead costs to be fixed costs. The first set of data that is shown below is...
-
What are the fundamental differences between preemptive and cooperative multitasking in an operating system, and in which scenarios would each be most effective ?
Study smarter with the SolutionInn App