《计算机网络自顶向下方法》第二章笔记(1)
(0)

应用层

principles of network applications

client-server

server:

  • always-on host
  • permanent IP address(server)
  • data centers for scaling

clients:

  • communicate with server
  • may be intermittently connected(间歇性连接)
  • may have dynamic IP addresses
  • do not communicate directly with each other

peer-to-peer (P2P)

  • no always-on server
  • arbitrary end systems directly communicate(任意端系统直连)
  • peers request service from other peers, provide service in return to other peers
  • self scalability – new peers bring new service capacity, as well as new service demands(自扩展性新的对等方产生工作负载也增加新的服务能力)
  • peers are intermittently connected and change IP addresses
  • complex management

Processes communicating

process: program running within a host

  • within same host, two processes communicate using inter-process communication (defined by OS)
  • processes in different hosts communicate by exchanging messages

clients, servers

  • client process: process that initiates communication
  • server process: process that waits to be contacted
  • applications with P2P architectures have client processes & server processes
  • 无论如何,在任意给定的一对进程之间的通信会话场景中,我们仍能将一个进程标识为客户,另一个进程标识为服务器。

Sockets(套接字)

  • process sends/receives messages to/from its socket
  • socket analogous to door 套接字和门类似
  • sending process shoves message out door发送进程把消息推出门(socket)
  • sending process relies on transport infrastructure on other side of door to deliver message to socket at receiving process(发送进程依赖于另一侧门的基础设施来传递信息给接收进程)
  • 套接字也被称为应用程序编程接口(application programming interface,API)
  • 开发者可以控制套接字在应用层端的一切。但对于套接字的运输层端基本没有控制权。只能选择运输层协议,也许能设定几个运输层参数

Addressing processes进程寻址

  • to receive messages, process must have identifier
  • host device has unique 32-bit IP address
  • identifier includes both IP address and port numbers associated with process on host.

可供应用程序使用的运输服务

data integrity 可靠数据传输
  • some apps (e.g., file transfer, web transactions) require 100% reliable data transfer
  • other apps (e.g., audio) can tolerate some loss
throughput吞吐量
  • some apps ("bandwith sensitive application"e.g., multimedia) require minimum amount of throughput to be “effective”
  • other apps (“elastic apps弹性应用”) make use of whatever throughput they get
timing

some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”

security

encryption, data integrity, …

Internet transport protocols services

TCP service:
  • reliable transport between sending and receiving process
  • flow control: sender won’t overwhelm(使应接不暇) receiver
  • congestion control(拥塞控制): throttle(节流) sender when network overloaded
  • connection-oriented(面向连接的): setup required between client and server processes
  • does not provide: timing, minimum throughput guarantee, security(目前有tcp加强版SSL)
UDP service:
  • unreliable data transfer between sending and receiving process
  • does not provide: reliability, flow control, congestion control, timing, throughput guarantee, security, or connection setup,

application-layer protocol

应用层协议定义了
  • 交换的报文类型,例如请求报文和响应报文
  • 各种报文类型的语法,如报文中的各个字段和这些字段是如何描述的
  • 字段的语义,即这些字段中信息的含义
  • 确定一定进程何时以及如何发送报文
Internet apps: application, transport protocols

Securing TCP
TCP & UDP
  • No encryption(无加密)
  • cleartext passwds sent into socket traverse Internet in cleartext
SSL (Secure Sockets Layer 安全套接层)
  • provides encrypted TCP connection
  • data integrity
  • end-point authentication
  • SSL is at app layer,apps use SSL libraries, that “talk” to TCP

Web and HTTP

webpage

  • web page consists of objects
  • object can be HTML file, JPEG image, Java applet, audio file,…
  • web page consists of base HTML-file which includes several referenced objects
  1. object is addressable by a URL, e.g.,

HTTP overview

HTTP: hypertext transfer protocol

Web’s application layer protocol
client/server model

client: browser that requests, receives, (using HTTP protocol) and “displays” Web objects

server: Web server sends (using HTTP protocol) objects in response to requests

uses TCP(http使用TCP协议而不是UDP):
  1. client initiates TCP connection (creates socket) to server, port 80
  2. server accepts TCP connection from client
  3. HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)
  4. TCP connection closed
HTTP is “stateless”(无状态)

server maintains no information about past client requests

HTTP connections

non-persistent HTTP(非持续)

  • at most one object sent over TCP connection
    ,connection then closed
  • downloading multiple objects required multiple connections
    ##### Round-Trip Time往返时间

一个短分组从客户到服务器然后再返回客户花费的时间

客户请求HTML基本文件到该客户收到这个文件花费的时间是两个RTT加上服务器传输HTML文件的时间

缺点
  1. 必须为每一个请求的对象建立和维护一个全新的连接。
  2. 每一个对象都要经过两倍RTT的交付时延

persistent HTTP(持续) 默认采用持续连接

multiple objects can be sent over single TCP connection between client, server

在采用持续连接的情况下,服务器在发送响应后保持该TCP连接打开。在相同的客户与服务器之间的后续请求和响应报文能够通过相同的连接进行传送。特别是,一个完整的Web页面可以用单个持续TCP连接进行传送。更有甚者,位于同一台服务器的多个Web页面在从该服务器发送给同一个客户时,可以在单个持续TCP连接上进行。可以一个接一个地发出对对象的这些请求,而不必等待对未决请求(流水线)的回答。一般来说,如果一条连接经过一定时间间隔(一个可配置的超时间隔)仍未被使用,HTTP服务器就关闭该连接。HTTP的默认模式是使用带流水线的持续连接。

HTTP报文格式

请求报文

  • 第一行:请求行(request line)

包括方法字段、url字段和HTTP版本字段

  • 后继行:首部行(header line)。例如Host指明对象所在的主机

使用get方法实体体为空。post方法才使用实体体。

响应报文

  • 状态行:协议版本字段、状态码和相应状态信息
  • 首部行
  • 实体体(主要部分)

常见状态码

200 OK:表示从客户端发送给服务器的请求被正常处理并返回;

204 No Content:表示客户端发送给客户端的请求得到了成功处理,但在返回的响应报文中不含实体的主体部分(没有资源可以返回);

206 Patial Content:表示客户端进行了范围请求,并且服务器成功执行了这部分的GET请求,响应报文中包含由Content-Range指定范围的实体内容。

301 Moved Permanently:永久性重定向,表示请求的资源被分配了新的URL,之后应使用更改的URL;

302 Found:临时性重定向,表示请求的资源被分配了新的URL,希望本次访问使用新的URL;

301与302的区别:前者是永久移动,后者是临时移动(之后可能还会更改URL)

303 See Other:表示请求的资源被分配了新的URL,应使用GET方法定向获取请求的资源;

302与303的区别:后者明确表示客户端应当采用GET方式获取资源

304 Not Modified:表示客户端发送附带条件(是指采用GET方法的请求报文中包含if-Match、If-Modified-Since、If-None-Match、If-Range、If-Unmodified-Since中任一首部)的请求时,服务器端允许访问资源,但是请求为满足条件的情况下返回改状态码;

307 Temporary Redirect:临时重定向,与303有着相同的含义,307会遵照浏览器标准不会从POST变成GET;(不同浏览器可能会出现不同的情况);

400 Bad Request:表示请求报文中存在语法错误;

401 Unauthorized:未经许可,需要通过HTTP认证;

403 Forbidden:服务器拒绝该次访问(访问权限出现问题)

404 Not Found:表示服务器上无法找到请求的资源,除此之外,也可以在服务器拒绝请求但不想给拒绝原因时使用;

500 Inter Server Error:表示服务器在执行请求时发生了错误,也有可能是web应用存在的bug或某些临时的错误时;

503 Server Unavailable:表示服务器暂时处于超负载或正在进行停机维护,无法处理请求;

cookie

1) cookie header line of HTTP response message
2) cookie header line in next HTTP request message
3) cookie file kept on user’s host, managed by user’s browser
4) back-end database at Web site

Web caches (proxy server)代理服务器

goal: satisfy client request without involving origin server

process

user sets browser: Web accesses via cache
browser sends all HTTP requests to cache

object in cache: cache returns object

else cache requests object from origin server, then returns object to client

cache acts as both client and server

server for original requesting client

client to origin server

typically cache is installed by ISP (university, company, residential ISP)

why ?

  • reduce response time for client request
  • reduce traffic on an institution’s access link
  • Internet dense with caches: enables “poor” content providers to effectively deliver content (so too does P2P file sharing)

Conditional GET

Goal: don’t send object if cache has up-to-date cached version;允许缓存器证实它储存的对象是真实的

  • no object transmission delay
  • lower link utilization(更低的链路利用)
条件
  1. 请求报文使用get方法
  2. 请求报文包含一个"If-Modified-Since"首部行
过程

cache: specify date of cached copy in HTTP request
If-modified-since: <date>

server: response contains no object if cached copy is up-to-date:
HTTP/1.0 304 Not Modified

electronic mail

Three major components:

  1. user agents
  2. mail servers
  3. simple mail transfer protocol: SMTP

User Agent

  • a.k.a. “mail reader”
  • composing, editing, reading mail messages
  • e.g., Outlook, Thunderbird, iPhone mail client
  • outgoing, incoming messages stored on server

mail servers:

  • mailbox contains incoming messages for user
  • message queue of outgoing (to be sent) mail messages

SMTP protocol :

between mail servers to send email messages

  • client: sending mail server
  • “server”: receiving mail server

detail

  1. uses TCP to reliably transfer email message from client to server, port 25
  2. direct transfer: sending server to receiving server
  3. three phases of transfer
  • handshaking (greeting)
  • transfer of messages
  • closure中止,关闭
  1. command/response interaction (like HTTP) 报文和回应有交互性
    commands: ASCII text(需要将二进制多媒体数据编码为ASCII码,传输后还原)

response: status code and phrase

  1. messages must be in 7-bit ASCII 限制为7位ASCII码
  2. SMTP将报文直接从SMTP客户端发送到SMTP服务端,不使用中间服务器。如果服务端服务器没有开机,客户会稍后继续尝试连接。

SMTP报文

  • 以一个只包含一个句号的行向服务器指示该报文结束。
  • SMTP使用持续连接:如果发送邮件服务器有几个报文发往同一个接收邮件服务器,可以通过一个TCP连接发送这些所有的报文。每个报文用一个新的MAIL FROM:开始,用一个独立的句点指示该邮件的结束,并且当且仅当所有邮件发送完后才发送QUIT。
  • 必须包含FROM:和TO:这两个首部行。

与HTTP对比

相同
  • 都用于从一台主机向另一台主机传送文件。
  • 持续的HTTP和SMTP都使用持续连接
不同
  • HTTP主要是一个拉协议(pull protocal) TCP连接是想接收文件的机器发起的。而SMTP是一个推协议(push protocal) TCP连接是由要发送该文件的机器发起的。
  • SMTP报文必须使用7比特ASCII码格式
  • 处理一个包含很多媒体类型的文档。HTTP把每个对象封装到它自己的HTTP报文中。SMTP把所有报文对象放在一个报文中。

邮件访问协议 Mail access protocols

pop3 (Post Office Protocol [RFC 1939])

三个阶段:

特许(authorization):用户代理发送(以明文形式)用户名和口令以鉴别用户

事务处理(transaction):用户代理取回报文;还能对报文做删除标记,取消报文删除标记,获取邮件统计信息

更新(update):客户发送quit命令后结束该POP3对话同时该邮件服务器删除那些被标记位删除的报文。

  • During a POP3 session between a user agent and the mail server, the POP3 server maintains some state information; in particular, it keeps track of which user messages have been marked deleted.However, the POP3 server does not carry state information across POP3 sessions. This lack of state information across sessions greatly simplifies the implementation of a POP3 server

IMAP: Internet Mail Access Protocol [RFC 1730]

  • An IMAP server will associate each message with a folder; when a message first arrives at the server, it is associated with the recipient’s INBOX folder. The recipient can then move the message into a new, user-created folder, read the message, delete the message, and so on. The IMAP protocol provides commands to allow users to create folders and move messages from one folder to another. IMAP also provides commands that allow users to search remote folders for messages matching specific criteria.Note that, unlike POP3, an IMAP server maintains user state information across IMAP sessions—for example, the names of the folders and which messages are associated with which folders
  • IMAP具有允许用户代理获取报文某些部分的命令

基于web的电子邮件

用户代理是浏览器,从浏览器到远程邮件服务器通信通过HTTP进行。而从邮件服务器发到另一个邮件服务器时仍然使用SMTP。e.g. gmail, Hotmail, Yahoo! Mail, etc.

本文为作者silent666发布,未经允许禁止转载!
上一篇 下一篇
评论
暂无评论 >_<
加入评论