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...
-
Horned Frogs Fine Cooking maintains its books using cash-basis accounting. However, the company recently borrowed $50,000 from a local bank, and the bank requires the company to provide annual...
-
a. Wildcat Oil Corporation drills an exploratory well during 2016 that finds oil, but not in commercially producible quantities at current oil prices. Since proved reserves are not found, Wildcat...
-
Various pension plan information of the Kerem Company for 2010 and 2011 is as follows: Required Fill in the blanks lettered (a) through (k). All the necessary information is listed. It is not...
-
Given the matrices A and B shown below, find B+ A. Rows: 2 -3 18 -10 -3 15 15 10 11 A = B = -18 9 1 -6 -6 0 3 11 Columns: 2 +
-
Following are separate financial statements of Michael Company and Aaron Company as of December 31, 2013 (credit balances indicated by parentheses). Michael acquired all of Aarons outstanding voting...
-
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.
-
Earlier as an example we used d c Î»Ì 0 /θ s to calculate the approximate lateral coherence distance for sunlight. Now find that same quantity, the diameter of the...
-
Explain the differences among the following. a. External auditors. b. Internal auditors. c. Government auditors.
-
A bicycle and rider of mass \(90 \mathrm{~kg}\) are travelling at a speed of \(15 \mathrm{~km} / \mathrm{h}\) on a level road. A brake is applied to the rear wheel which is \(0.7 \mathrm{~m}\) in...
-
Paraphrase the section or sections of the scope and/or opinion paragraphs that refer or allude to the following terms: a. Material. b. Risk. c. Sampling.
-
Which of the following is not a quality control standard? a. Independence in fact and appearance should be maintained at all organizational levels. b. Personnel should be hired who possess the...
-
The drum diameter of a single-block brake is \(1 \mathrm{~m}\). It sustains \(240 \mathrm{Nm}\) of torque at \(400 \mathrm{rpm}\). The coefficient of friction is 0.32 . The distance of the fulcrum...
-
Evaluate the indefinite integral. cos(T/x) dx
-
At the beginning of the year, Lam Ltd. had total assets of $800,000 and total liabilities of $500,000. Use this information to answer each of the following independent questions. (a) If Lam's total...
-
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?
-
ABC Costing Method what is the the "Using Gross Profit %"for the 3 empty grey spaces ... Note the existing profit is not 52.17% for the second empty box Question 1 The sustainability manager is...
-
A health savings plan Question 14 options: a) may be an involuntary payroll deduction for an employee. b) allows users to save money that is deducted after taxes to pay for future medical expenses....
-
Madison Manufacturing wants to import a machine from Germany. However, the company's head of manufacturing is reluctant to spend the time required to obtain a letter of credit that the German...
Study smarter with the SolutionInn App