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...
-
Anna is about to buy a house on a hill. Prior to the purchase she obtains a promise from Betty, the owner of the adjacent property, that Betty will not build any structure that would block Annas...
-
Sherene Lynch opened a medical practice titled Sherene Lynch M.D., Inc. During January, the first month of operations, the business experienced the following events: Requirement 1. Analyze the...
-
Describe a situation in which the sales value at splitoff method cannot be used but the NRV method can be used for joint-cost allocation.
-
Using one-year of daily returns calculate the volatility and beta of the stock. What does this information tell you about the stock's risk profile? ( Note: Please submit your calculations. I want to...
-
Which series has the highest beta. BraveNewCoin Liquid Index for Bitcoin 1D BNC Trading Brave Ne Yellow Green Blue Orange
-
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...
-
Two loudspeakers \(42.0 \mathrm{~m}\) apart and facing each other emit identical \(115 \mathrm{~Hz}\) sinusoidal sound waves in a room where the sound speed is \(345 \mathrm{~m} / \mathrm{s}\). Susan...
-
If the speed of sound is determined by an experiment and found to be 3 5 5 m / s instead of the usual 3 4 5 m / s , what factor ( s ) beside experimental error could account for this increase?
-
Describe moneys' four essential functions- medium of exchange, unit of accounting, a temporary store of value, and a standard of deferred payment? Describe the new alternative to fiat money-...
-
Small and Medium-sized Enterprises in periods of prolonged economic crisis may suffer from economic downturns " but is this indeed the case? Are they valid reasons, why small firms may have different...
-
1. In the sixteenth century a father-and-son team, by the name of , produced a compound microscope consisting of a simple tube with lenses at each end. a. van Leeuwenhoek b. Semmelweis c. Janssen d....
-
A typical optic fiber has a thickness of only 6.00 x 10 nm. Consider a beam from a standard He-Ne laser that has a wavelength equal to 633 nm. Suppose this beam is incident upon two parallel slits...
-
Describe the COM+ and CORBA standards for component infrastructure and communication. Which standard would you choose to support a new large-scale information system? Why?
-
Velshi Printers has contracts to complete weekly supplements required by fortysix customers. For the year 2018, manufacturing overhead cost estimates total $600,000 for an annual production capacity...
-
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?
-
Avondale Industries reported the following data for 2022: Current liabilities $55,000 Interest expense.. $6,000 Noncurrent liabilities. 60,000 Income tax expense. 2,400 Stockholders' equity. 50,000...
-
Apex Company prepared the statement of cash flows for the current year that is shown below: Apex Company Statement of Cash Flows-Indirect Method Operating activities: Net income Adjustments to...
-
Jefferson Company's demand for its only product exceeds its manufacturing capacity. The company provided the following information for the machine whose limited capacity is prohibiting the company...
Study smarter with the SolutionInn App