Chapter 1.Introduction_1.1Introduca

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.html

寫經過計算機網絡交互的程序時,創造的第一個是協議(protocol),一個他們的程序如何交互的一致的意見.在學習協議(protocol)設計思想以前,必須就哪些項目應該開始通訊以及何時須要響應作出高層次的決定(有道翻譯).例如,一個web服務器就是一個典型的後臺運行程序,爲了發送network messages來回應來自網絡上的請求.協議(protocol)的另外一方面是web客戶端,好比瀏覽器,老是隨時和服務器開始交互.大多數網絡感知應用程序都使用這個組織到客戶機和服務器(有道翻譯).決定性的是客戶端老是趨向於簡化的協議和代碼自己開始請求(不知道翻譯的對不對).固然一些更復雜的網絡應用也須要用到異步回調通訊,在服務器開始向客戶端發送信息時。可是對於應用程序來說更常見的仍是基礎的client/server模型。web

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.編程

在某個時刻客戶端一般會和一個服務器交互,例如瀏覽器,咱們可能會在上面和多個服務器進行交互,十分鐘爲一週期.可是從服務器的角度來看,同一時間會和多個客戶端進行交互,對於服務器和多個客戶端交互來講這不是不尋常的.咱們會展現在Figure 1.2後,對於服務器在同一時間下和多個客戶端交互咱們會經過不一樣的方法.api

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協議套件.也被稱爲Internet protocol套件.舉個例子,web客戶端和服務器交互經過傳輸控制層協議,或TCP.TCP,反過來,使用Internet protocol,IP和數據鏈路層交互.若是客戶端和服務器都在以太網上,咱們將會安排在 Figure 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.網絡

即便客戶端和服務器交互是在使用應用層協議,傳輸層交互使用TCP協議.請注意,客戶端和服務器之間的實際信息流是沿着協議棧的一端向下的(有道翻譯),經過網絡,另外一方面又沿着協議棧向上.還須要注意的是客戶端和服務器其是典型的用戶進程,而TCP和IP協議一般是內核協議棧的一部分(有道翻譯).咱們已經在圖1.3的右側標記了四個層。app

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.異步

TCP和IP並非咱們惟一要討論的協議,一些客戶端和服務器使用User Datagram protocol(UDP)來替代TCP,咱們將會在第二章詳細討論這兩個協議.此外,咱們還將使用IP這一術語,可是從20世紀80年代早期開始使用的協議被正式稱爲IP version 4 (IPv4)(有道翻譯).一個新的版本IPv6在1990年中期提出來,在不久的未來頗有可能會替代掉IPv4.本文包含了同時使用IPv4和IPv6的網絡應用.附錄A提供IPv4和IPv6的對照,隨着其餘的協議咱們會討論的.async

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中咱們展現客戶端和服務器在不一樣的局域網不一樣的局域網上,兩個局域網經過路由器鏈接在同一個廣域網.

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.

路由器是廣域網的構建模塊(有道翻譯).目前最大的廣域網就是Internet.不少公司創建了他們本身的廣域網和他們私有的廣域網,而這些私有廣域網路可能鏈接到Internet,也可能不鏈接到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服務器.

To simplify all our code, we define our own wrapper functions for most of the system functions that we call throughout the text. We can use these wrapper functions most of the time to check for an error, print an appropriate message, and terminate when an error occurs. We also show the test network, hosts, and routers used for most examples in the text, along with their hostnames, IP addresses, and operating systems.

爲了簡化咱們的代碼,咱們定義了本身的函數包爲了大多數的系統函數.咱們爲文本中調用的大多數系統函數定義了本身的包裝器函數。(有道翻譯)咱們能夠屢次使用這些函數包去檢查錯誤,打印合適的信息並在錯誤發生時終止。咱們也能夠檢測網絡,主機,路由器.連同他們的主機名,IP地址和操做系統.咱們還展現了文本中大多數示例使用的測試網絡、主機和路由器,以及它們的主機名、IP地址和操做系統。(有道翻譯)

Most discussions of Unix these days include the term "X," which is the standard that most vendors have adopted. We describe the history of POSIX and how it affects the Application Programming Interfaces (APIs) that we describe in this text, along with the other players in the standards arena.

最近關於Unix的大多數討論都包括術語「X」,這是大多數供應商採用的標準。咱們將描述POSIX的歷史,以及它如何影響本文中描述的應用程序編程接口(api),以及標準領域中的其餘參與者。(有道翻譯)

相關文章
相關標籤/搜索