[翻譯練習]UNIX Network Programming Volume1, Third Edition 1.1(001)

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服務器端程序與客戶端程序配合使用。

 

 

 

發佈了139 篇原創文章 · 獲贊 12 · 訪問量 47萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章