The file server of Fig. 6-6 is far from perfect and could use a few improvements. Make
Question:
The file server of Fig. 6-6 is far from perfect and could use a few improvements. Make the following modifications.(a) Give the client a third argument that specifies a byte range.(b) Add a client flag ?w that allows the file to be written to the server.
Figure 6-6
Transcribed Image Text:
#include
#include #include #include #include /* This is the server code / #include #define SERVER PORT 12345 /* arbitrary, but client & server must agree */ /* block transfer size */ #define BUF_SIZE 4096 #define QUEUE SIZE 10 int main(int argc, char *argv]) { int s, b, I, fd, sa, bytes, on = 1; char buf[BUF_SIZEJ; struct sockaddr_in channel; I* buffer for outgoing file / /* holds IP address */ /* Build address structure to bind to socket. */ memset(&channel, 0, sizeof(channel)); channel.sin_family = AF_INET; channel.sin_addr.s_addr = htonl(INADDRANY); channel.sin_port = htons(SERVER_PORT); /* zero channel */ * Passive open. Wait for connection. */ S = socket(AF_INET, SOCK STREAM, IPPROTO_TCP); * create socket */ if (s < 0) fatal("socket failed"); setsockopt(s, SOLSOCKET, SO REUSEADDR, (char •) &on, sizeof(on)); b= bind(s, (struct sockaddr *) &channel, sizeof(channel)); if (b < 0) fatal("bind failed"); I= isten(s, QUEUE_SIZE); if (I < 0) fatal("listen failed"); /* Socket is now set up and bound. Wait for connection and process it. */ while (1) { sa = accept(s, 0, 0); if (sa < 0) tatal("accept failed"); /* specify queue size */ /* block for connection request / read(sa, buf, BUF_SIZE); /* read file name from socket */ /* Get and return the file. */ fd = open(buf, O_RDONLY); if (fd < 0) tatal("open failed"); /* open the file to be sent back */ while (1) { bytes = read(fd, buf, BUF_SIZE); /* read from file */ if (bytes <= 0) break; write(sa, buf, bytes); } close(fd); close(sa); } /* check for end of file */ /* write bytes to socket / /* close file */ /* close connection */
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 63% (11 reviews)
a To give the client a third argument that specifies a byte range we can modify the clientserver co...View the full answer
Answered By
FELIX NYAMBWOGI
I have been tutoring for over 5 years, both in person and online. I have experience tutoring a wide range of subjects, including math, science, English, and history. I have also worked with students of all ages, from elementary school to high school.
In addition, I have received training in effective tutoring strategies and techniques, such as active listening, questioning, and feedback. I am also proficient in using online tutoring platforms, such as Zoom and Google Classroom, to effectively deliver virtual lessons.
Overall, my hands-on experience and proficiency as a tutor has allowed me to effectively support and guide students in achieving their academic goals.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
The purpose of this exercise is to give you an opportunity to create the tables for Bearcat Incorporated. The tables themselves are based on the relations that appear in the following figure. L1:...
-
Rewrite the server of Fig. 6-6 as a true Web server using the GET command for HTTP 1.1. It should also accept the Host message. The server should maintain a cache of files recently fetched from the...
-
The Liquid Chemical Company manufactures and sells a range of high-grade products. Many of these products require careful packaging. The company has a special patented lining made that it uses in...
-
Svetlana (45) and Petro (43) are both employed and each have their own group benefit plan that provides family coverage. Svetlana's birthday is in June and Petro's is in December. The couple has one...
-
Three hundred thousand years after the Big Bang, the average temperature of the universe was about 3000 K. a) At what wavelength would the blackbody spectrum peak for this temperature? b) In what...
-
Requisition materials from materials area to department A. LO.1
-
Does it matter how the overhead variance is disposed? Explain.
-
A social psychologist wishes to test the assertion that our attitude toward other people tends to reflect our perception of their attitude toward us. A randomly selected member of each of 12 couples...
-
Homework: Ch 9 Homework B-Graded December 2004, the Account Rotivate balance of Center Application Inc is $155.000. The Allowance for Bed Debts account has a $17.210 debt balance Destor Application...
-
Katie is a one-third owner of an S corporation. After a falling out with the other shareholders, Katie signed an agreement early in January 2014. Under the terms of the agreement, Katie took $...
-
Use the trace route (UNIX) or tracert (Windows) programs to trace the route from your computer to various universities on other continents. Make a list of transoceanic links you have discovered. Some...
-
One common function that all network protocols need is to manipulate messages. Recall that protocols manipulate messages by adding/striping headers. Some protocols may break a single message into...
-
Fluid passes through this set of thin closely spaced blades. What flow rate \(q\) is required for the velocity \(V\) to be \(10 \mathrm{ft} / \mathrm{s}\) ? 2 ft Radial line 30 P4.25
-
When to use a tuple vs list vs dictionary in Python? Explain some benefits of Python
-
What is Lambda Functions in Python? How do I modify a string in python?
-
1. How will you check if a class is a child of another class? 2. What is init method in python?
-
1. What are lists and tuples? What is the key difference between the two? 2. What is Scope in Python?
-
1. What is an Interpreted language? 2. What is a dynamically typed language?
-
Write a task that has an integer signal and a file name as parameters. Each line of the file contains a delay value and an integer. The task reads a line from the file, waits for the delay time,...
-
Using the theoretical sampling strategy, how many samples of size 4 (n = 4) can be drawn from a population of size: (a) N = 5? (b) N = 8? (c) N = 16? (d) N = 50?
-
Figure 8.28 shows a switch in a virtual-circuit network. Find the output port and the output VCI for packets with the following input port and input VCI addresses: a. Packet 1: 3, 78 b. Packet 2: 2,...
-
What is TSI and what is its role in time-division switching?
-
Figure 8.27 shows a switch (router) in a datagram network. Find the output port for packets with the following destination addresses: a. Packet 1: 7176 b. Packet 2: 1233 Output Destination address...
-
true- false statement (c) Cost-based accounting is conservative
-
C. Inventory Revaluation Outdoor Recreation has the following three trailers in stock at the end of the year: Model #1103 #1204 #1305 Original cost 5,500 7,200 9,000 Expected sales price 5,700 8,500...
-
true- false statement (8) Unanimity implies that shareholders have no incentive to use their voting rights. (1) With corporate income tax, retention dominates dividends
Study smarter with the SolutionInn App