基于微信公众平台的电子点餐系统的设计与实现外文翻译资料

 2022-11-04 16:56:47

Web servers dish out billions of web pages a day. They tell you the weather, load up

your online shopping carts, and let you find long-lost high-school buddies. Web

servers are the workhorses of the World Wide Web. In this chapter, we:

bull; Survey the many different types of software and hardware web servers.

bull; Describe how to write a simple diagnostic web server in Perl.

bull; Explain how web servers process HTTP transactions, step by step.

Where it helps to make things concrete, our examples use the Apache web server and

its configuration options.

Web Servers Come in All Shapes and Sizes

A web server processes HTTP requests and serves responses. The term “web server”

can refer either to web server software or to the particular device or computer dedi-

cated to serving the web pages.

Web servers comes in all flavors, shapes, and sizes. There are trivial 10-line Perl

script web servers, 50-MB secure commerce engines, and tiny servers-on-a-card. But

whatever the functional differences, all web servers receive HTTP requests for

resources and serve content back to the clients (look back to Figure 1-5).

Web Server Implementations

Web servers implement HTTP and the related TCP connection handling. They also

manage the resources served by the web server and provide administrative features to

configure, control, and enhance the web server.

The web server logic implements the HTTP protocol, manages web resources, and

provides web server administrative capabilities. The web server logic shares responsi-

bilities for managing TCP connections with the operating system. The underlying

operating system manages the hardware details of the underlying computer system

and provides TCP/IP network support, filesystems to hold web resources, and pro-

cess management to control current computing activities.

Web servers are available in many forms:

bull; You can install and run general-purpose software web servers on standard com-

puter systems.

bull; If you donrsquo;t want the hassle of installing software, you can purchase a web server

appliance, in which the software comes preinstalled and preconfigured on a

computer, often in a snazzy-looking chassis.

bull; Given the miracles of microprocessors, some companies even offer embedded

web servers implemented in a small number of computer chips, making them

perfect administration consoles for consumer devices.

Letrsquo;s look at each of those types of implementations.

General-Purpose Software Web Servers

General-purpose software web servers run on standard, network-enabled computer

systems. You can choose open source software (such as Apache or W3Crsquo;s Jigsaw) or

commercial software (such as Microsoftrsquo;s and iPlanetrsquo;s web servers). Web server

software is available for just about every computer and operating system.

While there are tens of thousands of different kinds of web server programs (includ-

ing custom-crafted, special-purpose web servers), most web server software comes

from a small number of organizations.

In February 2002, the Netcraft survey (http://www.netcraft.com/survey/) showed three

vendors dominating the public Internet web server market (see Figure 5-1):

bull; The free Apache software powers nearly 60% of all Internet web servers.

bull; Microsoft web server makes up another 30%.

bull; Sun iPlanet servers comprise another 3%.

Figure 5-1. Web server market share as estimated by Netcraftrsquo;s automated survey

Take these numbers with a few grains of salt, however, as the Netcraft survey is com-

monly believed to exaggerate the dominance of Apache software. First, the survey

counts servers independent of server popularity. Proxy server access studies from

large ISPs suggest that the amount of pages served from Apache servers is much less

than 60% but still exceeds Microsoft and Sun iPlanet. Additionally, it is anecdotally

believed that Microsoft and iPlanet servers are more popular than Apache inside cor-

porate enterprises.

Web Server Appliances

Web server appliances are prepackaged software/hardware solutions. The vendor pre-

installs a software server onto a vendor-chosen computer platform and preconfig-

ures the software. Some examples of web server appliances include:

bull; Sun/Cobalt RaQ web appliances (http://www.cobalt.com)

bull; Toshiba Magnia SG10 (http://www.toshiba.com)

bull; IBM Whistle web server appliance (http://www.whistle.com)

Appliance solutions remove the need to install and configure software and often

greatly simplify administration. However, the web server often is less flexible and

feature-rich, and the server hardware is not easily repurposeable or upgradable.

Embedded Web Servers

Embedded servers are tiny web servers intended to be embedded into consumer prod-

ucts (e.g., printers or home appliances). Embedded web servers allow users to

administer their consumer devices using a convenient web browser interface.

Some embedded web servers can even be implemented in less than one square inch,

but they usually offer a minimal feature set. Two examples of very small embedded

web servers are:

bull; IPic match-head sized web server (http://www-ccs.cs.umass.edu/~shri/iPic.html)

bull; NetMedia SitePlayer SP1 Ethernet Web Server (http://www.siteplayer.com)

A Minimal Perl Web Server

If you want to build a full-featured HTTP server, you have some work to do. The

core of the Apache web server has over 50,000 lines of code, and optional processing

modules make that number much bigger.

All this software is needed to suppor

剩余内容已隐藏,支付完成后下载完整资料


Web服务器每天会分发出数十亿的Web页面。这些页面可以告诉你天气情况,装在在线商店的购物车,还能帮你找到许久为联系的高中同学。Web服务器是万维网的骨干。本章将介绍以下话题。

  • 对多种使用不同类型软硬件的web服务器进行调查。
  • 介绍如何使用Perl编写简单的诊断性Web服务器。
  • 一步一步地解释Web服务器是如何处理HTTP事务的。

为了对问题进行具体的说明,例子中使用了Apache Web服务器及其配置选项。

5.1 各种形状和尺寸的Web服务器

Web服务器会对HTTP请求进行处理并提供响应。属于“Web服务器”可以用来表示Web服务器的软件,也可以用来便是提供Web页面的特定设备或计算机。

Web服务器有着不同的风格、形状和尺寸。有普通的10行Perl脚本的Web服务器、50MB的安全商用引擎以及极小的卡上服务器。但不管功能有何差异,所有的Web服务器都能够接受请求资源的HTTP请求,将内容会送给客户端(参见图1-5)。

5.1.1 Web服务器的实现

Web服务器实现了HTTP和相关的TCP连接处理。负责管理Web服务器提供的资源,以及对Web服务器的配置、控制及扩展方面的管理。

Web服务器逻辑实现了HTTP协议、管理着Web资源,并负责提供Web服务器的管理功能。Web服务器逻辑和操作系统共同负责管理TCP连接。底层操作系统负责管理底层计算机系统的硬件细节,并提供了TCP/IP网络支持、负责装载Web资源的文件系统以及控制当前计算机活动的进程管理功能。

Web服务器有各种不同的形式。

  • 可以在标准的计算机系统上安装并运行通用的软件Web服务器。
  • 如果不想那么麻烦地去安装软件,可以买一台Web服务器设备,通常会是一台安装在时髦机架上的计算机,里面的软件会预装并配置好。
  • 随着微处理器奇迹般地出现,有些公司甚至可以在少量计算机芯片上实现嵌入式Web服务器,使其成为完美的(便携式)消费类设备管理控制台。

我们分别来看看这些实现方式。

5.1.2 通用软件Web服务器

通用软件Web服务器都运行在标准的、有网络功能的计算机系统上。可以选择开源软件(比如Apache或W3C的jigsaw)或者商用软件(比如微软和iplanet的Web服务器)。基本上所有的计算机和操作系统中都有可用的Web服务器软件。

尽管不同类型的Web服务器程序有数万个(包括定制的和特殊用途的Web服务器),但大多数Web服务器软件都来自少数几个组织

2002年2月,Netcraft调查(http://www.netcraft.com/survey/)显示有三家厂商主宰了公共因特网服务器市场(参见图5-2)。

  • 免费的Apache软件占据了所有因特网Web服务器中大约60%的市场。
  • 微软的Web服务器占据了另外30%。
  • Sun的iplanet占据了另外的3%。

图5-1 Netcraft的自动化调查估计的Web服务器市场份额

但这些数据也不能尽信,通常大家都认为Netcraft调查会夸大Apache软件的优势。首先,在调查计算服务器的时候没有考虑其流行程度。各大ISP的代理服务器访问研究表明,Apache服务器提供的页面数量远小于60%,但仍然超过了微软和Sun的iPlanet。然而,据说微软和iPlanet服务器在公司企业中要比Apache更受欢迎。

5.1.3 Web服务器设备

Web服务器设备(Web server appliance)是预先打包好的软硬件解决方案。厂商会在他们选择的计算机平台上预先安装好软件服务器,并将软件配置好。下面是一些Web服务器设备的例子:

应用解决方案不再需要安装及配置软件,通常可以极大地简化管理工作。但是Web服务器通常不太灵活,特性不太丰富,而且服务器硬件也不太容易重用或升级。

5.1.3 嵌入式Web服务器

嵌入式服务器(embeded server)是要嵌入到消费类产品(比如打印机或家用设备)中去的小型Web服务器。嵌入式Web服务器允许用户通过便捷的Web浏览器接口来管理其消费者设备。

有些嵌入式Web服务器甚至可以在小于一平方英寸的空间内实现,但通常只能提供最小特性功能集。下面是两种非常小的嵌入式Web服务器实例:

5.2 最小Perl Web服务器

要构建一个特性完备的HTTP服务器,是需要做一些工作的.Apache Web 服务器的内核有超过50000行的代码,那些可选处理模块的代码量更是远远超过这个数字.

这个软件所要做的就是支持HTTP/1.1的各种特性:丰富的资源支持、虚拟主机、访问控制、日志记录、配置、监视和性能特性。在这里,可以用少于30行的Perl代码来常见一个最小的可用HTTP服务器。我们来看看这是怎么实现的。

例5-1显示了一个名为type-o-serve收到了请求报文,就会将报文打印在屏幕上,然后等待用户输入(粘贴)一条响应报文,并将其回送给客户端。通过这种方式,type-o-serve假扮成一台Web服务器,记录下确切的HTTP请求报文,并允许用户送回任意的HTTP响应报文。

这个简单的 type-o-serve实用程序并没有实现大部分的HTTP功能,但它是一种很有用的工具,产生服务器响应报文的方式与Telnet产生客户端请求报文的方式相同(参见例5-1)。

可以从http://www.http-guide.com/tools/type-o-serve.pl上下载type-o-serve程序。

例5-1 type-o-serve ——用于HTTP调试的最小型PerlWeb服务器

#!/usr/bin/perl

use Socket;

use Carp;

use FileHandle;

# (1) use port 8080 by default, unless overridden on command line

$port = (@ARGV ? $ARGV[0] : 8080);

# (2) create local TCP socket and set it to listen for connections

$proto = getprotobyname(tcp);

socket(S, PF_INET, SOCK_STREAM, $proto) || die;

setsockopt(S, SOL_SOCKET, SO_REUSEADDR, pack('l', 1)) || die;

bind(S, sockaddr_in($port, INADDR_ANY)) || die;

listen(S, SOMAXCONN) || die;

# (3) print a startup message

printf(' lt;lt;lt;Type-O-Serve Accepting on Port %dgt;gt;gt; ',$port);

while (1)

{

# (4) wait for a connection C

$cport_caddr = accept(C, S);

($cport,$caddr) = sockaddr_in($cport_caddr);

C-gt;autoflush(1);

# (5) print who the connection is from

$cname = gethostbyaddr($caddr,AF_INET);

printf(' lt;lt;lt;Request From %sgt;gt;gt; ',$cname);

# (6) read request msg until blank line, and print on screen

while ($line = lt;Cgt;)

{

print $line;

if ($line =~ /^ /) { last; }

}

Example 5-1. type-o-serve—a minimal Perl web server used for HTTP debugging (continued)

# (7) prompt for response message, and input response lines,

# sending response lines to client, until solitary '.'

printf(' lt;lt;lt;Type Response Followed by .gt;gt;gt; ');

while ($line = lt;STDINgt;)

{

$line =~ s/ //;

$line =~ s/ //;

if ($line =~ /^./) { last; }

print C $line . ' ';

}

close(C);

}

图5-2显示了Joe的五金商店的管理员是如何用type-o-serve来测试HTTP通信的。

  • 首先,管理员启动了type-o-serve诊断服务器,在一个特定的端口上监听。由于Joe的五金商店已经有一个产品化的Web服务器在监听80端口了,所以管理员用下面这条命令在端口8080(可以选择任意未用端口)上启动了type-o-serve服务:%type-o-serve.pl 8080
  • 只要type-o-serve开始运行了,就可以将浏览器指向这个Web服务器。在图5-2中,浏览器指向了http://www.joes-hardware.com:8080/foo/bar/blath.txt
  • type-o-serve程序收到来自浏览器的HTTP请求报文,并将HTTP请求报文的内容打印在屏幕上。然后type-o-serve诊断工具会等待用户输入一条简单的响应报文,后面跟着只有一个句号的空行
  • type-o-serve将HTTP响应报文会送给浏览器,浏览器辉县市响应报文的主体。

图5-2 type-o-server使用程序让用户输入服务器响应,将其回送给客户端

5.3 实际的Web服务器会做些什么

例5-1显示的Perl服务器是一个Web服务器的小例子。最先进的商用Web服务器要比它复杂得多,但他们确实执行了几项相同的任务,如图5-3所示。

  1. 建立连接——接受一个客户端连接,或者如果不希望与这个客户端建立连接,就将其关闭。
  2. 接收请求——从网络中读取一条HTTP请求报文。
  3. 处理请求——对请求报文进行解释,并采取行动。
  4. 访问资源——访问报文中指定的资源
  5. 构建响应——创建带有正确部首的HTTP响应报文。
  6. 发送响应——将响应会送给客户端
  7. 记录事务处理过程——将与已完成实物有关的内容记录在一个日志文件中。

图5-3 基本Web服务器请求的步骤

接下来的7个小节重点说明了Web服务器是怎样实现这些基本任务的。

5.4 第一步——接受客户端连接

如果客户端已经打开了一条到服务器的持久连接,可以使用那条连接来发送它的请求。否则,客户端需要打开一条新的到服务器的连接。

5.4.1 处理新连接

客户端请求一条到Web服务器的TCP连接时,Web服务器会建立连接,判断连接的另

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[140342],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。