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...
-
Transitions Inc. is an import-export company specializing in products from Asia and the West Coast. It can borrow in the debt market at 8%. Its cost of equity with 40% D/V ratio is 12%. Its corporate...
-
Do we have a strategic planning process in place? Is it used appropriately to help our organization achieve its goals?
-
The information in the table is from the statement of cash flows for a company at four different points in time (A, B, C, and D). Negative values are presented in parentheses. InstructionsFor each...
-
1. A bartender sells drinks to customers and, when they pay cash, he does not record the sale at the cash register and keeps the cash. 2. A bartender knows that there is a special on vodka tonight so...
-
Alexander Smith and his wife Allison are married and file a joint tax return for 2019. The Smiths live at 1234 Buena Vista Drive, Orlando, FL 32830. Alexander is a commuter airline pilot but took 6...
-
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...
-
A cubical box is filled with sand and weighs 890N. We wish to "roll" the box by pushing horizontally on one of the upper edges. (a) What minimum force is required? (b) What minimum coefficient of...
-
Root cause analysis with fish bone diagram and Forecast analysis for the case study "Agarwal Automobiles: Fuel station forecasting and inventory management" with peer reviewed journal references.
-
Suppose that MPI_COMM WORLD consists of the eight processes 0, 1, 2, 3, 4, 5, 6, and 7, and suppose the following code is executed: int sum = my_sum; int iLevel = 0; MPI Status status; for (int...
-
Measuring and monitoring It is the SMT's view that the reduction in accident frequency rate alone clearly indicates that the slips and trips campaign was a success discuss possible limitations of...
-
Identify some of the repercussions of high staff turnover at Eswatini Electricity Company ( EEC ) , especially on critical and skilled employees occupying key positions. Further, differentiate...
-
1. Make sure your report server is setup correctly. 2. Deploy all 10 reports and Shared Data Source. 3. Take a snapshot of each report (Parameters Visible) and paste them in 1 MS Word Document. The...
-
Analyze the bouncing ball (Problem 9.6) using the WKB approximation. (a) Find the allowed energies, E n , in terms of m, g, and . (b) Now put in the particular values given in Problem 9.6(c), and...
-
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...
-
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?
-
business law A partner may actively compete with the partnership True False
-
A company provided the following data: Selling price per unit $80 Variable cost per unit $45 Total fixed costs $490,000 How many units must be sold to earn a profit of $122,500?
-
Suppose a 10-year, 10%, semiannual coupon bond with a par value of $1,000 is currently selling for $1,365.20, producing a nominal yield to maturity of 7.5%. However, it can be called after 4 years...
Study smarter with the SolutionInn App