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...
-
Irwin Schiff is a self-styled tax rebel who has made a career, and substantial profit, out of his tax protest activities. On February 7, Schiff appeared live on CBS News Nightwatch, a late-night...
-
Presented here is information for Telco, Inc., for the year ended December 31,2010. Requirements 1. What is the beginning stockholders equity of Telco, Inc.? 2. What is the ending stockholders equity...
-
Griffin and Lasky, Inc. (G&L) supplies industrial automation equipment and machine tools to the automotive industry. G&L uses the percentage of completion method for recognizing revenue on its...
-
A stock is currently priced at $91.30. In one year it is expected to pay a dividend and be priced at $95.35. If the stock's return is 5.20%, then what is the dividend expected to be in one year?...
-
Cardinal Company is considering a five-year project that would require a $2,975,000 investment in equipment with a useful life of five years and no salvage value . The company's discount rate is 14%....
-
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.
-
In each part suppose that the augmented matrix for a system of linear equations has been reduced by row operations to the given row-echelon form. Solve the system. (a) (b) 725 421 310 100 632 591 841...
-
A mass of 1 0 7 g exerts a force on an area of 0 . 5 8 m 2 on a planet where the acceleration due to gravity g = 0 . 1 0 0 m s - 2 . What is the pressure in S . I. units?
-
In this discussion, we'll examine how Donald Trump's views have been disseminated across social media. In the following article, Dwoskin and Timberg (2020), discuss the causes and effects of the...
-
Frederick Corp. is a public company and has 1 0 0 , 0 0 0 common shares outstanding. In 2 0 1 7 , the company reported income from continuing operations before income tax of $ 2 , 7 1 0 , 0 0 0 ....
-
8. Fossils of prokaryotes go back billion years. a. 4.0 to 5.0 b. 3.5 to 4.0 c. 2.5 to 3.0 d. 2.2 to 2.7 9. Molds belong to which of the following groups of eukaryotic organisms? a. Protozoans b....
-
Max uses a Ford F-350 Truck (it is a dually with a lift kit and has a 6.7L Power Stroke Turbo Diesel engine; Gross Vehicle Weight = 9,900 pounds) 100% for business. He acquired and placed the vehicle...
-
What is infrastructure? In what ways do hardware and system software qualify as infrastructure?
-
Funds are separate fiscal and accounting entities, each with its own self-balancing set of accounts. The newly established Society for Ethical Teachings maintains two funds-a general fund for...
-
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?
-
Alex purchases lamps and books. In 2020, price of books were $4 per book and she purchased 100 books. She also purchases 10 lamps at a price of $10/lamp. a/ sketch an indifference budget line diagram...
-
The demand for eggs is given by Qd=30-5P and the where Qd is the quantity of eggs demanded in '000 kgs and P is the price of an egg. The supply is given byQs=6+P where Qs is the quantity of egg...
-
Compute the convolution y[n] = x[n] * h[n] a) for (x[n])=(1, 2, -1, 0.3) and (h[n]) = (-1, -2, 2, 1} b) for (x[n]) (2, 0, -3, 1) and (h[n]) = (1, 0, 2, -1}
Study smarter with the SolutionInn App