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: 75% (8 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)?
-
List the disadvantages of the alphabetic derivation code.
-
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...
-
Lower-of-Cost-or-MarketJournal Entries Dover Company began operations in 2010 and determined its ending inventory at cost and at lower-of-cost-or-market at December 31, 2010, and December 31, 2011....
-
Fickle Sickles collects 15,000 checks per 365-day year with average amount $170 and total delay 5 days. A lockbox system would reduce that delay to 3 days, and it would also reduce FISI's check...
-
A college chemistry instructor thinks the use of embedded tutors (tutors who work with students during regular class meeting times) will improve the success rate in introductory chemistry courses....
-
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.
-
Perth Inc.'s bank statement from Main Street Bank at August 31, 2017, gives the following information. A summary of the Cash account in the ledger for August shows the following: balance, August 1,...
-
A view that groups items is very useful when: Select an answer: you do not have permission to create a filtered view. you have a large number of documents in a library. all of these the view cannot...
-
Small cluster size ( ( N ) ) is desirable to Question 3 3 Answer a . . Increase user capacity b . . Reduce CCI c . . Increase traffic intensity d . . Increase SNIR
-
TMP236A2DCKT Temperature sensor, and PIC12F1840-E/P, can they interface with each other? Why?
-
When was Ethereum's genesis block mined? a . . 2 0 1 3 2 0 1 3 b . . 2 0 1 5 2 0 1 5 c . . 2 0 1 8 2 0 1 8 d . . 2 0 0 9 2 0 0 9
-
SharePoint is installed on _ _ _ _ _ . _ _ _ _ _ . Select an answer: a server a local device both of these
-
Juanita is the sole shareholder of Belize Corporation (a calendar-year S corporation). She is considering revoking the S election. It is February 1, year 1. What options does Juanita have for timing...
-
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.
-
Module 06 Course Project - Whistleblower Hotline Throughout the course, we have explored the legal and ethical factors that impact marketing decisions. Now, it's time to put that knowledge into...
-
How to create a class Vector that can be initialized with a list of numbers Implement a method to print a user-friendly string representation of the vector Overload the + operator to add two vectors...
-
Title: Request for Proposal - Market Research on Cheese in Canada Background Contexts: It has been documented that the consumption of cheese is an important aspect of Canadian food culture. Recent...
Study smarter with the SolutionInn App