[翻译练习]UNIX Network Programming Volume1, Third Edition 1.1(001)

来源:互联网 发布:驾照考试模拟软件下载 编辑:程序博客网 时间:2024/05/20 18:49

Chapter 1. Introduction

1.1 Introduction

When writing programs that communicate across a computer network, one must first invent a protocol, an agreement on how those programs will communicate. Before delving into the design details of a protocol, high-level decisions must be made about which program is expected to initiate communication and when responses are expected. For example, a Web server is typically thought of as a long-running program (or daemon) that sends network messages only in response to requests coming in from the network. The other side of the protocol is a Web client, such as a browser, which always initiates communication with the server. This organization into client and server is used by most network-aware applications. Deciding that the client always initiates requests tends to simplify the protocol as well as the programs themselves. Of course, some of the more complex network applications also require asynchronous callback communication, where the server initiates a message to the client. But it is far more common for applications to stick to the basic client/server model shown in Figure 1.1.

1.1概述

在进行计算机网络编程之前必须先建立一个协议,此协议描述程序如何通讯。在对协议进行详细设计之前,必须在较高层次上做一些规定(decisions,关于哪个程序进行初始化(initiate)通信以及何时进行响应。比如, Web服务是一个长期运行的程序(或后台程序),它只有在网络上有请求时才会做出响应,发出网络信息。协议的另一端是Web客户端,比如浏览器程序,它总是初始化与服务器之间的通讯。大部分网络应用程序都组织成客户端和服务器架构。规定客户端总是初始化需求,这样可以使协议和程序本身更趋简单。当然,另外一些较为复杂的程序也需要异步回调(asynchronous callback)通信,这时服务器将向客户端发送初始化信息。但采用C/S(Client/Server)架构的程序则最为普遍。C/S架构如图1.1所示

Figure 1.1. Network application: client and server.

Clients normally communicate with one server at a time, although using a Web browser as an example, we might communicate with many different Web servers over, say, a 10-minute time period. But from the server's perspective, at any given point in time, it is not unusual for a server to be communicating with multiple clients. We show this in Figure 1.2. Later in this text, we will cover several different ways for a server to handle multiple clients at the same time.

Web浏览器为例,尽管我们在10分钟的时间里可能会与不同的Web服务器连接,但在一个时间点,客户端只与一个服务器相连。对服务器来说,在多数时间里它经常会与许多客户端相连(如图1.2所示)。我们将在本书的后面,介绍服务器如何同时管理多个客户端,并且相关的方法还不止一个。

Figure 1.2. Server handling multiple clients at the same time.

 

The client application and the server application may be thought of as communicating via a network protocol, but actually, multiple layers of network protocols are typically involved. In this text, we focus on the TCP/IP protocol suite, also called the Internet protocol suite. For example, Web clients and servers communicate using the Transmission Control Protocol, or TCP. TCP, in turn, uses the Internet Protocol, or IP, and IP communicates with a datalink layer of some form. If the client and server are on the same Ethernet, we would have the arrangement shown in Figure 1.3.

客户端和服务器端程序看起来是通过一个网络协议相连接,但实际上有多层协议参与工作。本书着重介绍TCP/IP协议族,又称互联网协议族。例如Web客户端和服务器端通讯要使用传输控制协议(Transmission Control Protocol),TCPTCP转而使用互联网协议(Internet Protocol)IPIP与某种形态的数据链路层通讯。如果客户端和服务器端在同一个以太网内,分层情况如图1.3所示。

Figure 1.3. Client and server on the same Ethernet communicating using TCP.

Even though the client and server communicate using an application protocol, the transport layers communicate using TCP. Note that the actual flow of information between the client and server goes down the protocol stack on one side, across the network, and up the protocol stack on the other side. Also note that the client and server are typically user processes, while the TCP and IP protocols are normally part of the protocol stack within the kernel. We have labeled the four layers on the right side of Figure 1.3.

尽管客户端和服务器端通讯使用一个应用协议(application protocol),传输层通讯却使用TCP。需要注意的是在客户端和服务器端之间的实际信息流,是在一侧的协议栈上面下行,通过网络,再从另一侧的协议栈下面上行。另外客户端和服务器是典型的同户进程,而TCP/IP协议一般是核心协议栈的一部分。我们已经在上图中右侧标注了这4个层。

TCP and IP are not the only protocols that we will discuss. Some clients and servers use the User Datagram Protocol (UDP) instead of TCP, and we will discuss both protocols in more detail in Chapter 2. Furthermore, we have used the term "IP," but the protocol, which has been in use since the early 1980s, is officially called IP version 4 (IPv4). A new version, IP version 6 (IPv6) was developed during the mid-1990s and could potentially replace IPv4 in the years to come. This text covers the development of network applications using both IPv4 and IPv6. Appendix A provides a comparison of IPv4 and IPv6, along with other protocols that we will discuss.

我们不仅要讨论TCPIP协议。一些客户端和服务器端程序也使用“用户数据报协议”(User Datagram Protocol (UDP))来代替TCP,我们将在第二章对二者进行详细讨论。此外,IP作为协议从20世纪80年代初就已经使用了,它更正规的称谓是IP版本4(IPv4).它的新版本IP版本6(IPv6)90年代中期开发出来,它将在未来逐渐取代IPv4.本书内容适用于IPv4IPv6.附录AIPv4IPv6进行比较,同时也讲解其它协议。

The client and server need not be attached to the same local area network (LAN) as we show in Figure 1.3. For instance, in Figure 1.4, we show the client and server on different LANs, with both LANs connected to a wide area network (WAN) using routers.

正像图1.3所表现的,客户端和服务器端不必存在于一个局域网内。如图1.4所示它们处于不同局域网内。不同的局域网由路由器(routers)连入广域网(wide area network(WAN)).

Figure 1.4. Client and server on different LANs connected through a WAN.

Routers are the building blocks of WANs. The largest WAN today is the Internet. Many companies build their own WANs and these private WANs may or may not be connected to the Internet.

路由器是广域网的组成模块。今天最大的广域网是互联网。有些公司建立自己的广域网,这种广域网既可连入互联网,也可以不那么做。

The remainder of this chapter provides an introduction to the various topics that are covered in detail later in the text. We start with a complete example of a TCP client, albeit a simple one, that demonstrates many of the function calls and concepts that we will encounter throughout the text. This client works with IPv4 only, and we show the changes required to work with IPv6. A better solution is to write protocol-independent clients and servers, and we will discuss this in Chapter 11. This chapter also shows a complete TCP server that works with our client.

本章余下的部分给出一些话题的概述,它们将在后面的章节详细讨论。我们以一个完整的TCP客户端程序开始讨论,尽管只是一个简单的程序,它却展现了一些函数调用和一些基本概念,这些概念将在本书后面不断的使用。这个客户端程序只在Ipv4下工作,我们同时教授如何修改以使其能在Ipv6下工作。更好的办法是编写协议无关程序,此话题将在11章讨论。本章同时介绍一个完整的TCP服务器端程序与客户端程序配合使用。

 

 

 

原创粉丝点击