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: 57% (7 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...
-
Discuss fully the difference between the "contexts" of Figure 16.1 and Figure 16.4. Figure 16.1 Figure 16.4 Treasurer 2. Investing & financing CHIEF FINANCIAL OFFICER Budgeting Managerial reporting...
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. What does Descartes' rule of signs tell us about the IRR(s) of this project? b. What does Norstrom's criterion tell us...
-
The number of internal disk drives (in millions) made at a plant in Taiwan during the past 5 years follows: a) Forecast the number of disk drives to be made next year, using linear regression. b)...
-
A space for storing boxes is 36 inches high. Each box is 6 inches high. A space of 9 inches must be left at the top.
-
There is a parcel of land next to the Playful Paws, Inc. building. Ellen, the owner of this property, approached John to discuss the idea of selling it to him. John is interested. Ellen knows that...
-
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...
-
Using holography (a method of producing an image without using a lens), an image of concentric circles is formed. The radius r of each circle varies directly as the square root of the wavelength of...
-
Layering multiple linear and logistic functions is best described as 1 1 point Non - Linear Network Logistic Regression Fully Connected Network
-
QUESTION 8 8 How is data at rest protected? a . . Encryption b . . Decryption c . . Read / / Write permissions d . . Network router
-
If I add more neurons to my neural network, what may I expect? 1 1 point Underfitting A perfect model Overfitting
-
Question 14 Not yet answered Marked out of 7.00 Flag question In 2023, Eduvos hopes to generate a substantial amount of profit and has therefore, decided to give 3% salary increase to all its...
-
32 Question 2 In the statement: height = input ("Enter your height in centimeters:") 3 pts ,what will be the data type of the value stored in the variable height?
-
Apple Union (AU), a C corporation with a March 31 year-end, uses the accrual method of accounting. If AU elects to be taxed as an S corporation, what will its year-end and overall method of...
-
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...
-
Write a Java program demonstrating method overloading and method overriding.
-
(i) The company made additional sales on 28 December. Both the sales and the cost of goods sold were not recorded in the accounts. Based on the specific identification cost flow assumption, the value...
-
Create a class in Python representing a geometric shape with methods to calculate its area and perimeter.
Study smarter with the SolutionInn App