标签:add function 多个 callback rem and hostname details could
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.
写通过计算机网络交互的程序时,创造的第一个是协议(protocol),一个他们的程序如何交互的一致的意见.在学习协议(protocol)设计思想之前,必须就哪些项目应该开始通信以及什么时候需要响应做出高层次的决定(有道翻译).例如,一个web服务器就是一个典型的后台运行程序,为了发送network messages来回应来自网络上的请求.协议(protocol)的另一方面是web客户端,比如浏览器,总是随时和服务器开始交互.大多数网络感知应用程序都使用这个组织到客户机和服务器(有道翻译).决定性的是客户端总是趋向于简化的协议和代码本身开始请求(不知道翻译的对不对).当然一些更复杂的网络应用也需要用到异步回调通信,在服务器开始向客户端发送信息时。但是对于应用程序来讲更常见的还是基础的client/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后,对于服务器在同一时间下和多个客户端交互我们会通过不同的方法.
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的右侧标记了四个层。
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的对照,随着其他的协议我们会讨论的.
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),以及标准领域中的其他参与者。(有道翻译)
Chapter 1.Introduction_1.1Introduca
标签:add function 多个 callback rem and hostname details could
原文地址:https://www.cnblogs.com/AI-Cobe/p/10209328.html