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...
-
Compare and contrast PGP and S/MIME. What are the advantages and disadvantages of each?
-
Consider heat transfer over a flat plate again but now include an additional term due to viscous heating. Show that the similarity method is applicable to this problem as well, and derive the...
-
Tel-Com Company, a telephone service and supply company, has just completed its fourth year of operations. The direct write-off method of recording bad debt expense has been used during the entire...
-
How do ethical considerations factor into the governance frameworks of collaborative consortia, particularly concerning data privacy, intellectual property rights, and equitable distribution of...
-
Saint Leo is developing a plan to promote their new Center in your hometown. The University's marketing director wants to use a varied and balanced approach to IMC. For each of the five IMC types...
-
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...
-
Find (i) The net area. (ii) The area of the following regions. Graph the function and indicate the region in question. The region bounded by y = x 1/2 and the x-axis between x = 1 and x = 4.
-
The output of workers at a factory depends on the number of supervisors hired (see the following table). The factory sells its output for $0.50 each, it hires 50 production workers at a wage of $100...
-
The demand for labor in Occupation A is L D = 20 -W, where LD = number of workers demanded for that occupation, in thousands. The supply of labor for Occupation A is L A = -1.25 + .5W. For Occupation...
-
You are involved in an investigation of charges that a large university in a small town is discriminating against female employees. You find that the salaries for professors in the nearly all-female...
-
Assume that a state government currently provides no child-care subsidies to working single parents, but it now wants to adopt a plan that will encourage labor force participation among single...
-
A study shows that for American high school dropouts, obtaining a General Equivalency Degree (GED) by part-time study after high school has very little payoff. It also shows, however, that for...
-
How has job searching for candidates and job placement for hiring managers changed in the digital age? In your opinion, have the changes had a positive or a negative effect? 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?
-
When a RACI matrix is being created, what person or group of people are assign an R for responsible?
-
a) What is arbitrage? And what are the different types of arbitrage? B) Can arbitrage strategies be risky when price convergence is not guaranteed? Clearly describe and outline 1 real-life example to...
-
Explain each segments of Financial Services Industry which are the BANKS, INSURANCE, AND ASSET MANAGEMENT . Explain each. Explain the updates on the 3 segments of Financial Services Industry (banks,...
Study smarter with the SolutionInn App