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
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
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服务器
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中咱们展现客户端和服务器在不一样的局域网不一样的局域网上,两个局域网经过路由器链接在同一个广域网.
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),以及标准领域中的其余参与者。(有道翻译)