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)?
-
The product costs relevant for output and product mix decisions. LO.1
-
Distinguish between work in process, finished goods, and cost of goods sold.
-
Consider the December transactions for Shine King Cleaning that were presented in Chapter 5. (Cost data has been removed from the sale transactions.) Dec 2 Purchased 600 units of inventory, $3,600,...
-
A company purchased a plot of land with a building on it for 720,000 dinars in cash, where the value is Fair to land at 60,000 dinars, fair value of buildings at 200,000 dinars, estimated cost Of...
-
Andrew Jackson's actions in the Seminole War were universally celebrated in Congress and throughout the nation eventually resulted in Spain relinquishing Florida ended in an embarassing series of...
-
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.
-
Is every zero-one square matrix that is symmetric and has zeros on the diagonal the adjacency matrix of a simple graph?
-
Q3. b) Discuss how each model can be applied in real-world organizational change scenarios.
-
In this question, you will work step-by-step through an optimization problem. A craftsman wants to make a cylindrical jewelry box that has volume, V, equal to 55 cubic inches. He will make the base...
-
Find f(x) if y = f(x) satisfies dy dx 60yx and the y-intercept of the curve y = f(x) is 6. f(x)
-
Data on the gasoline tax per gallon ( in cents ) as of a certain date for the 5 0 U . S . states and the District of Columbia are shown below. State Gasoline Tax per Gallon State Gasoline Tax per...
-
Write a function report card where the user can enter each of his grades, after which the program prints out a report card with GPA. Remember to ask the user how many classes he took (think - why...
-
Write structural Verilog code for a module that is an N-bit serial-in, serial-out rightshift register. Inputs to the shift register are bit signals: SI (serial input), Sh (shift enable), and CLK....
-
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.
-
You need to calculate the total number of items ordered by customers from Texas. Two-letter state abbreviations are in Column B and quantity ordered is in Column G. There are 200 rows in the...
-
Cully Company needs to raise $22 million to start a new project and will raise the money by selling new bonds. The company will generate no internal equity for the foreseeable future. The company has...
-
A.1)If the inflation rates in the British pound and the US $ are 4% and 1% respectively, while the exchange rate is 1 pound exchanges for $2, what will the future spot rate be? 2) What is the meaning...
Study smarter with the SolutionInn App