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...
-
A permutation block (P-box) in a modern block cipher is an example of a keyless transposition cipher. What does this statement mean? (See Figure 31.8 in the text.) Figure 31.8 2 3. 2 Straight...
-
Consider the flat-plate heat transfer to be solved by the similarity approach. Show all the details leading to Eq. (18.15). What are the boundary conditions on \(\theta\) ? Extend your MATLAB code to...
-
Mansfield Corporation had 2013 sales of $100 million. The balance sheet items that vary directly with sales and the profit margin are as follows: Percent Cash ..............5% Accounts receivable...
-
We have a game of invasion of France by the Allies and defense by the Germans. Both can play C (Calais) or N (Normandy). The following matrix shows the payoffs of each player in utility levels (more...
-
1. What opportunities did Melissa identify, and how did she capitalize on those opportunities? 2. How did Melissas background help her identify and tackle the problems she discovered in the beauty...
-
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.
-
(a) Draw a simple frequency polygon using the data in question 23. (b) Draw a relative frequency histogram of these data. In Question 23 16 1 13 12 1 16 12 16 15 16 11 13 16 1211
-
In 1942, the government promulgated regulations that prohibited the manufacture of many types of garments by workers who did the sewing, stitching, and knitting in their homes. If these prohibitions...
-
Suppose the wage rate that is paid at a particular firm is W = 5 + 0.5T, where T = the number of years that the worker has been employed at the firm. The marginal revenue product, which is measured...
-
Suppose that a least squares regression yields the following estimate: where W is the hourly wage rate (in dollars) and A is the age (in years). A second regression from another group of workers...
-
Calculate the own-wage elasticity of demand for occupations a, b, and c below. E D and W are the original employment and wage. E' D and W' are the new employment and wage. State whether the demand is...
-
A tenant is liable for injuries to an invitee resulting from a defect that could have been discovered using reasonable care even if the tenant did not actually discover it. True False
-
What is an ATS, and how does it affect the way you prepare a resume?
-
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?
-
Discuss at least five of the formatting decisions you would have to make when typing a table. Compare the decisions you provided to those of two of your classmates. Do you agree or disagree with the...
-
1-2. Draw graphs of the following functions using transformations: 1. y = 2x-1 x-2' 2. y log2x+1|- 3.
-
Assume a simultaneous open market purchase of 100 million from the Bank of England and a repayment of a discount loan of 5 million from Bank A to the Bank of England. Show the overall change in their...
Study smarter with the SolutionInn App