版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机网络及应用技术计算中心 林龙新2022-4-241暨南大学计算中心主要参考书目1. 计算机网络与因特网(第五版)机械工业出版社2. 计算机网络与因特网(第四版)机械工业出版社3. Internetworking with TCP/IP Volume I (Principles,Protocols and Architecture ) Douglas.E.Comer 清华大学出版社4. Interconnections Second Edition Bridges, routers,Switches and Internetworking Protocols Radia Perlman 清
2、华大学出版社5. computer networks (the fourth edition) Andrew S.Tanenbaum 清华大学出版社Chapter 3 Internet Applications and Network Programming Topics Covered3.1 Introduction 3.2 Two Basic Internet Communication Paradigms 3.3 Connection-Oriented Communication 3.4 The Client-Server Model of Interaction 3.5 Charact
3、eristics of Clients and Servers 3.6 Server Programs and Server-Class Computers 3.7 Requests, Responses, and Direction of Data Flow 3.8 Multiple Clients and Multiple Servers 3.9 Server Identification and Demultiplexing 3.10 Concurrent Servers 3.11 Circular Dependencies Among Servers 3.12 Peer-to-Peer
4、 Interactions 3.13 Network Programming and the Socket API Topics Covered3.14 Sockets, Descriptors, and Network I/O 3.15 Parameters and the Socket API 3.16 Socket Calls in a Client and Server 3.17 Socket Functions Used by Both Client and Server 3.18 The Connection Function Used Only by a Client 3.19
5、Socket Functions Used Only by a Server 3.20 Socket Functions Used with the Message Paradigm3.21 Other Socket Functions 3.22 Sockets, Threads, and Inheritance 3.1 Introduction The Internet offers users a rich diversity of servicesnone of the services is part of the underlying communication infrastruc
6、tureInternet provides a general purpose mechanism on which all services are builtand individual services are supplied by application programs that run on computers attached to the InternetIt is possible to devise new services without changing the InternetChapter covers two key concepts of Internet a
7、pplications:describes the conceptual paradigm that applications follow when they communicate over the Internetpresents the details of the socket Application Programming Interface (socket API) that Internet applications 73.1 Introduction Internet application programmers can get started easilyIt is po
8、ssible to create Internet applications without knowing how networks operate However, understanding network protocols and technologies allows them to write efficient and reliable code that enables applications to scale across many sitesLater parts of the text provide the necessary information by expl
9、aining data communications and protocols used to form the I3.2 Two Basic Internet Communication Paradigms The Internet supports two basic communication paradigms:3.2.1 Stream Transport in the Internet 3.2.2 Message Transport in the Internet Figure 3.1 summarizes the 3.2.1 Stream Transport in the Int
10、ernet Stream denotes a paradigm in which a sequence of bytes flows from one application program to anotherInternets mechanism arranges two streams between a pair of communicating applications, one in each directionThe network accepts input from either application, and delivers the data to the other
11、applicationThe stream mechanism transfers a sequence of bytes without attaching meaning to the bytes and without inserting boundariesA sending application can choose to generate one byte at a time, or can generate blocks of bytesThe network chooses the number of bytes to deliver at any timethe netwo
12、rk can choose to combine smaller blocks into one large block or can divide a large block into smaller blocks 2009 Pearson Education Inc., Upper Saddle River, NJ. All rights 3.2.2 Message Transport in the Internet In a message paradigm, the network accepts and delivers messagesEach message delivered
13、to a receiver corresponds to a message that was transmitted by a senderthe network never delivers part of a message, nor does it join multiple messages togetherif a sender places exactly n bytes in an outgoing message, the receiver will find exactly n bytes in the incoming messageThe message paradig
14、m allows delivery in different forms:Unicasta message can be sent from an application on one computer directly to an application on another, 1-to-1Multicasta message can be multicast to some of the computers on a network, 1-to-manyBroadcasta message can be broadcast to all computers on a given netwo
15、rk, 1-to-3.2.2 Message Transport in the Internet Message service does not make any guaranteesSo messages may beLost (i.e., never delivered)Duplicated (more than one copy arrives)Delivered out-of-orderA programmer who uses the message paradigm must insure that the application operates correctlyeven i
16、f packets are lost or reordered Most applications require delivery guaranteesProgrammers tend to use the stream service except in special situationssuch as video, where multicast is needed and the application provides support to handle packet reordering and lossThus, we will focus on the stream 3.3
17、Connection-Oriented Communication The Internet stream service is connection-oriented It operates analogous to a telephone call:two applications must request that a connection be createdonce it has been established, the connection allows the applications to send data in either directionfinally, when
18、they finish communicating, the applications request that the connection be terminatedAlgorithm 3.1 summarizes the 3.4 The Client-Server Model of Interaction The first step in Algorithm 3.1 raises a question: how can a pair of applications that run on two independent computers coordinate to guarantee
19、 that they request a connection at the same time?The answer lies in a form of interaction known as the client-server modelA server starts first and awaits contactA client starts second and initiates the connectionFigure 3.2 summarizes the interactionSubsequent sections describe how specific services
20、 use the client-server modelApplication programs known as clients and servers handle all services in the I3.4 The Client-Server Model of Interaction 3.5 Characteristics of Clients and ServersMost instances of client-server interaction have the same general characteristicsA client software:Is an arbi
21、trary application program that becomes a client temporarily when remote access is needed, but also performs other computationIs invoked directly by a user, and executes only for one sessionRuns locally on a users personal computerActively initiates contact with a serverCan access multiple services a
22、s needed, but usually contacts one remote server at a timeDoes not require especially powerful computer 163.5 Characteristics of Clients and ServersA server software:Is a special-purpose, privileged program Is dedicated to providing one service that can handle multiple remote clients at the same tim
23、eIs invoked automatically when a system boots, and continues to execute through many sessionsRuns on a large, powerful computerWaits passively for contact from arbitrary remote clientsAccepts contact from arbitrary clients, but offers a single serviceRequires powerful hardware and a sophisticated op
24、erating system (OS)3.6 Server Programs and Server-Class Computers Term server refers to a program that waits passively for communicationNot to the computer on which it executesHowever, when a computer is dedicated to running one or more server programs, the computer itself is sometimes called a serv
25、erHardware vendors contribute to the confusion because they classify computers that have fast CPUs, large memories, and powerful operating systems as server machinesFigure 3.3 illustrates the 3.6 Server Programs and Server-Class Computers 3.7 Requests, Responses, and Direction of Data Flow Client an
26、d server? Which side initiates contact?Once contact has been established, two-way communication is possible (i.e., data can flow from a client to a server or from a server to a client)In some cases, a client sends a series of requests and the server issues a series of responses (e.g., a database cli
27、ent might allow a user to look up more than one item at a time)3.8 Multiple Clients and Multiple Servers Allowing a given computer to operate multiple servers is useful becausethe hardware can be shareda single computer has lower system administration overhead than multiple computer systemsexperienc
28、e has shown that the demand for a server is often sporadica server can remain idle for long periods of timean idle server does not use the CPU while waiting for a request to arriveIf demand for services is low, consolidating servers on a single computer can dramatically reduce cost without significa
29、ntly reducing 213.8 Multiple Clients and Multiple Servers A computer can run:A single clientA single serverMultiple copies of a client that contact a given serverMultiple clients that each contact a particular serverMultiple servers, each for a particular serviceAllowing a computer to operate multip
30、le clients is useful because services can be accessed simultaneouslyFor example, a user can have three (3) windows open simultaneously running three (3) applications: one that retrieves and displays emailanother that connects to a chat serviceand a third running a web 3.9 Server Identification and D
31、emultiplexing How does a client identify a server? The Internet protocols divide identification into two pieces:An identifier for the computer on which a server runsAn identifier for a service on the computerIdentifying a computer?Each computer in the Internet is assigned a unique 32-bit identifier
32、known as an Internet Protocol address (IP address)A client must specify the servers IP addressTo make server identification easy for humans, each computer is also assigned a name, and the Domain Name System (DNS) described in Chapter 4 is used to translate a name into an address Thus, a user specifi
33、es a name such as rather than an integer 233.9 Server Identification and Demultiplexing Identifying a service?Each service available in the Internet is assigned a unique 16-bit identifier known as a protocol port number (or port number) Examples, email port number 25, and the web port number 80When
34、a server begins executionit registers with its local OS by specifying the port number for its serviceWhen a client contacts a remote server to request servicethe request contains a port numberWhen a request arrives at a serversoftware on the server uses the port number in the request to determine wh
35、ich application on the server computer should handle the requestFigure 3.4 summarizes the basic 3.9 Server Identification and Demultiplexing 3.10 Concurrent Servers The steps in Figure 3.4 imply that a server handles one client at a timeAlthough a serial approach works in a few trivial cases, most s
36、ervers are concurrentThat is, a server uses more than one thread of controlConcurrent execution depends on the OS being usedConcurrent server code is divided into two piecesa main program (thread) a handlerThe main thread accepts contact from a client and creates a thread of control for the clientEa
37、ch thread of control interacts with a single client and runs the handler 263.10 Concurrent Servers After handling one client the thread terminatesThe main thread keeps the server alive after creating a thread to handle a requestthe main thread waits for another request to arriveIf N clients are simu
38、ltaneously using a concurrent server, N+1 threads will be running: the main thread (1) is waiting for additional requestsand N threads are each interacting with a single 3.11 Circular Dependencies Among ServersIn practice, the distinction blurs because a server for one service can act as a client fo
39、r anotherFor example, before it can fill in a web page, a web server may need to become a client of a databaseA server may also become the client of a security service (e.g., to verify that a client is allowed to access the service).Programmers must be careful to avoid circular dependencies among se
40、rversFor example, consider what can happen if a server for service X becomes a client of service X, which becomes a client of service X, which becomes a client of XThe chain of requests can continue indefinitely until all three servers exhaust resourcesThe potential for circularity is especially hig
41、h when services are designed independently because no single programmer controls all 283.12 Peer-to-Peer Interactions If a single server provides a given servicethe network connection between the server and the Internet can become a bottleneckFigure 3.5 illustrates the 3.12 Peer-to-Peer Interactions
42、 Can Internet services be provided without creating a central bottleneck?One way to avoid a bottleneck forms the basis of file sharing known as a peer-to-peer (P2P) architectureThe scheme avoids placing data on a central serverdata is distributed equally among a set of N serversand each client reque
43、st is sent to the appropriate servera given server only provides 1/N of the datathe amount of traffic between a server and the Internet is 1/N as much as in the single-server architectureServer software can run on the same computers as clientsFigure 3.6 illustrates the 3.12 Peer-to-Peer Interactions
44、 3.13 Network Programming and the Socket API The interface an application uses to specify communication is known as an Application Program Interface (API)Appendix 1 contains a simplified API (with only seven functions)example code that demonstrates how such an API can be used to create Internet appl
45、ications, including a working web serverDetails of an API depend on the OS One particular API has emerged as the de facto standard for software that communicates over the Internetknown as the socket API, and commonly abbreviated socketsThe socket API is available for many OSsuch as Microsofts Window
46、s systems as well as various UNIX systems, including L3.14 Sockets, Descriptors, and Network I/O Because it was originally developed as part of the UNIX OS, the socket API is integrated with I/OWhen an application creates a socket to use for Internet OS returns a small integer descriptor that identi
47、fies the socketThe application then passes the descriptor as an argumentwhen it calls functions to perform an operation on the socket (e.g., to transfer data across the network or to receive data)In many OS, socket descriptors are integrated with other I/O descriptorsas a result, an application can
48、use the read and write operations for socket I/O or I/O to a 3.15 Parameters and the Socket API Socket programming differs from conventional I/O An application must specify many details, such as the address of a remote computerthe protocol port numberand whether the application will act as a client
49、or as a server To avoid having a single socket function with many parameters, designers of the socket API chose to define many functionsAn application creates a socket, and then invokes functions for detailsThe advantage of the socket approach is that most functions have three or fewer parametersThe
50、 disadvantage is that a programmer must remember to call multiple functions when using socketsFigure 3.7 summarizes key functions in the socket API3.16 Socket Calls in a Client and Server Figure 3.8 illustrates the sequence of socket calls made by a typical client and server that use a stream connec
51、tionThe client sends data first and the server waits to receive dataIn practice, some applications arrange for the server to send first (i.e., send and recv are called in the reverse order)3.17 Socket Functions Used by Both Client and Server Readers are encouraged to check the book for the details o
52、f these functions3.17.1 The Socket Function 3.17.2 The Send Function 3.17.3 The Recv Function 3.17.4 Read and Write with Sockets 3.17.5 The Close Function 3.18 The Connection Function Used Only by a Client Clients call connect to establish a connection with a specific server. The form is:connect (so
53、cket, saddress, saddresslen)Argument socket is the descriptor of a socket to use for the connectionReaders are encouraged to check the book for the 3.19 Socket Functions Used Only by a Server Readers are encouraged to check the book for the details of these functions3.19.1 The Bind Function 3.19.2 The Listen Function 3.19.3 The Accept Function 3.20 Socket Function
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 摄影棚使用免责协议书
- 2026年民政领域购买服务知识测试题
- 2026年国家安全法及维护国家安全任务职责公民组织义务测试
- 2026年跨领域知识学习与实践指南
- 2026年企业员工健康知识竞赛题库
- 2026年第三次全国土壤普查成果应用知识竞赛
- 2026年建筑起重机械司机安全知识测试题
- 2026年世界历史大事件知识竞赛试题
- 2026年智慧环卫清扫保洁调度知识测试
- 2026年村社高价彩礼治理知识问答库
- 人教A版高中数学选择性必修第二册《导数在研究函数中的应用》评课稿
- 超声波清洗机的系统设计(plc)大学论文
- 浮头式换热器课程设计说明书
- 脊柱侧弯三维矫正
- 轧钢厂安全检查表
- YY/T 0299-2022医用超声耦合剂
- JJG 968-2002烟气分析仪
- 尿素-化学品安全技术说明书(MSDS)
- GB 16357-1996工业X射线探伤放射卫生防护标准
- FZ/T 01104-2010机织印染产品取水计算办法及单耗基本定额
- 四川省房屋建筑和市政基础设施项目工程总承包招标评标综合评估法
评论
0/150
提交评论