Rewrite the server of Fig. 6-6 as a true Web server using the GET command for HTTP
Question:
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 disk and serve requests from the cache when possible.
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: 80% (10 reviews)
The server of Fig 66 can be modified to become a true Web server using the GET command for HTTP 11 a...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
-
A multithreaded Web server is organized as shown in Fig. 7-21. It takes 500 sec to accept a request and check the cache. Half the time the file is found in the cache and returned immediately. The...
-
True or false? a. A user requests a Web page that consists of some text and three images. For this page, the client will send one request message and receive four response messages. b. Two distinct...
-
True or false: a. If stored video is streamed directly from a Web server to a media player, then the application is using TCP as the underlying transport protoco\' b. When using RTP, it is possible...
-
Consider the following function. def f(x): a = [] while x > 0: a.append(x) f(x-1) A new object of type list is created for each recursive invocation of f. True or False
-
How many fundamental fermions are there in a carbon dioxide molecule (CO2)?
-
Should the order be accepted?What is the change in income? What if? the setup activity had 50 hours of unused capacity. How does this affect your analysis? WaGA Inc. has a idle capacity.Recently WaGa...
-
The Lowe Company's income statement and comparative balance sheets as of December 31 of 2019 and 2018 are presented below: During the year, Lowe Company sold equipment for \(\$ 27,000\) cash that...
-
Prime Contractors (Prime) is a privately owned company that contracts with the U.S. government to provide various services under multiyear (usually five-year) contracts. Its principal services are as...
-
A B C D E
-
The finance director of RM plc is considering several investment projects and has collected the following information about them. Projects D and E are mutually exclusive. The capital available for...
-
Numerous people have registered DNS names that consist of www.word.com, where word is a common word. For each of the following categories, list five such Web sites and briefly summarize what it is...
-
Search the Internet for some court case involving copyright versus fair use and write a 1-page report summarizing your findings.
-
Explain what useful information is derived from index-number trend analysis.
-
Discuss the challenges of designing for mobile devices and responsive design.
-
Five-year` zero -coupon` bond` with` a `face` value `of `$1,000 `is `currently `selling` for` $826.50. `Assume` that` coupon` payments `are `normally `semi-annual. `What` is` the `bond's `YTM
-
Summerdahl Resort's common stock is currently trading at $26 a share. The stock is expected to pay a dividend of $1.25 a share at the end of the year (D 1 = $1.25), and the dividend is expected to...
-
Discuss how a company's neutral policy such as requiring everyone to wear the same uniform can sometimes be interpreted as discrimination. Can you think of other "neutral" sounding policies can...
-
John purchased an equipment for BHD 25,000 on 1 January 2013, it had an estimated useful life of 5 years, and it was depreciated using reducing balance method at a rate of 20% and residual value of...
-
Provide a summarization of the role accounting information systems plays in providing accurate and effective accounting information to internal and external stakeholders in context to the selected IT...
-
When you weigh yourself on good old terra firma (solid ground), your weight is 142 lb. In an elevator your apparent weight is 121 lb. What are the direction and magnitude of the elevator's...
-
Using Figure 7.16, tabulate the attenuation (in dB) of an optical fiber for the indicated wavelength and distances. Figure 7.16 100 50 10 0.5 0.1 0.05 0.01 800 1000 1200 1400 1600 1800 Wavelength...
-
How does sky propagation differ from line-of-sight propagation?
-
Name the advantages of optical fiber over twisted-pair and coaxial cable.
-
Sally is the HIM director at Memorial Hospital and has been asked to compose a record retention policy for the hospital. What should be her first consideration in determining how long paper and...
-
Your firm, which operates in the mining sector, is considering a proposal to build a new processing plant on the site of one of its vacant warehouses. The new building will cost $100 million, while...
-
Suppose you buy an 8% percent annual coupon bond for $1,100. The bond has 10 years to maturity. The interest is paid once a year. Five years from now, the interest rates have increased by 3% and you...
Study smarter with the SolutionInn App