Assume we want to make the TCP client program in Table 25.2 more generic to be able
Question:
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.
Transcribed Image Text:
Table 25.2 Echo client program using UDP // UDP echo client program #include "headerFiles.h" int main (int arge, char* argv[ ]) // Three arguments to be checked later // Declare and define variables int s; I/ Socket descriptor 6. // Length of string to be echoed // Server name int len; char* servName; I/ Server port I/ String to be echoed // Data buffer int servPort; 10 char* string; char buffer [256 + 1]; 12 I/ Server socket address struct sockaddr_in servAddr; I/ Check and set program arguments if (argc !=3) 13 14 15 16 printf ("Error: three arguments are needed!"); exit(1): 19 servName=argv[1]; servPort = atoi (argv[2]); string = argv[3]; I/ Build server socket address memset (&servVAddr, 0, sizeof (servAddr)); servAddr.sin_family = AF_INET; inet_pton (AF_INET, servName, &servAddr.sin addr): servAddr.sin port = htons (servPort): // Create socket if ((s = socket (PF_INET, SOCK_DGRAM, 0) < 0); perror ("Error: Socket failed!"): exit (1); I/ Send echo string len = sendto (s, string, strlen (string), 0, (struct sockaddr)&servAddr, sizeof (servAddr); I/ Receive echo string recvfrom (s, buffer, len, 0, NULL, NULL); // Print and verify echoed string 38 buffer [len] = '\0'; printf ("Echo string received: "; fputs (buffer, stdout); I/ Close the socket 40 41 close (s);s 43 // Stop the program 44 exit (0): 45 J// End of echo client program
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 60% (5 reviews)
Instead of using just one buffer we need to have two buffers recvBuff...View the full answer
Answered By
Aysha Ali
my name is ayesha ali. i have done my matriculation in science topics with a+ . then i got admission in the field of computer science and technology in punjab college, lahore. i have passed my final examination of college with a+ also. after that, i got admission in the biggest university of pakistan which is university of the punjab. i am studying business and information technology in my university. i always stand first in my class. i am very brilliant client. my experts always appreciate my work. my projects are very popular in my university because i always complete my work with extreme devotion. i have a great knowledge about all major science topics. science topics always remain my favorite topics. i am also a home expert. i teach many clients at my home ranging from pre-school level to university level. my clients always show excellent result. i am expert in writing essays, reports, speeches, researches and all type of projects. i also have a vast knowledge about business, marketing, cost accounting and finance. i am also expert in making presentations on powerpoint and microsoft word. if you need any sort of help in any topic, please dont hesitate to consult with me. i will provide you the best work at a very reasonable price. i am quality oriented and i have 5 year experience in the following field.
matriculation in science topics; inter in computer science; bachelors in business and information technology
_embed src=http://www.clocklink.com/clocks/0018-orange.swf?timezone=usa_albany& width=200 height=200 wmode=transparent type=application/x-shockwave-flash_
4.40+
11+ Reviews
14+ 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...
-
Assume we want to change the Stop-and-Wait protocol and add the NAK (negative ACK) packet to the system. When a corrupted packet arrives at the receiver, the receiver discards the packet, but sends a...
-
Assume we want to connect two isolated hosts together to let each host communicate with the other. Do we need a link-layer switch between the two? Explain.
-
The hot dog cooker described in the chapter heats hot dogs by connecting them to 120 V household electricity. A typical hot dog has a mass of 60 g and a resistance of 150 N. How long will it take...
-
Crane Cove Seafoods Limited Partnership is a limited partnership set up by the Eskasoni First Nation in Nova Scotia to manage the band's involvement in the commercial fishery. The balance sheet and...
-
The table below gives the average June and December temperatures (in Fahrenheit) for eight cities in the United States. City June December Anchorage 55.0 18.6 Bismarck 64.7 16.2 Boston 67.7 34.7...
-
Repeat the previous problem, but assume that the cost of installation is to be repaid at \(7 \%\) interest over 15 years and that the electricity costs escalate at \(10 \%\) per year. Compare the NPV...
-
Wyalusing Industries has manufactured prefabricated houses for over 20 years. The houses are constructed in sections to be assembled on customers lots. Wyalusing expanded into the precut housing...
-
The treasurer of a multinational corporation needs USD 5 million. DBS gives him a quote SGD/USD 1.3607 -1.3615. (a) At what rate will the multinational corporation buy USD? (b) How much will the...
-
On July 31, 2019, Ping Company purchased 90% of Santos Company?s common stock for $2,010,000 cash. Immediately after the acquisition, the two companies? balance sheets were as follows: Santos Company...
-
Explain which entity provides service and which one receives service in the client-server paradigm.
-
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...
-
Up To 10,000 Retail Stores Could Close This Year Up to 10,000 U.S. storefronts could disappear by the end of 2021. Consumers prefer the safety of shopping online during the Covid19 pandemic. Source:...
-
List 5 advantage and 5 disadvantages of over the counter medication ?
-
How do integrated transportation systems leverage advanced traffic flow modeling and optimization algorithms to improve mobility and reduce congestion in urban areas ?
-
If a bank is not BASEL 1 compliant what the bank needs to do to ensure compliance? And also give recommendations about banks NEt interest margin.
-
Dillon Products manufactures various machined parts to customer specifications. The company uses a job-order costing system and applies overhead cost to jobs on the basis of machine-hours. At the...
-
Provide examples of each of the following: a- Direct labour b- Indirect expenses
-
The dataset StudentSurvey has information from males and females on the number of hours spent exercising in a typical week. Computer output of descriptive statistics for the number of hours spent...
-
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....
-
How are the value components of a key-value database and a document database different?
-
Briefly explain the difference between row-centric and column-centric data storage.
-
What is the difference between a column and a super column in a column family database?
-
The wheels of a skateboard roll without slipping as it accelerates at 0.45 m/s down an 80-m-long hill. Part A If the skateboarder travels at 1.5 m/s at the top of the hill, what is the average...
-
A 2.30 g air-inflated balloon is given an excess negative charge, q = -3.50 10-8 C, by rubbing it with a blanket. It is found that a charged rod can be held above the balloon at a distance of d =...
-
A positive charge q = 2.60 C on a frictionless horizontal surface is attached to a spring of force constant k as in the figure shown below. When a charge of 42 = -8.350 C is placed 9.50 cm away from...
Study smarter with the SolutionInn App