TCP协议

来源:互联网 发布:济南软件外包服务 编辑:程序博客网 时间:2024/05/22 14:13

最近阅读了一下TCP协议的RFC规范:RFC793

记录一下里面比较重要的地方,写几篇读书笔记记录下,以方便后面回头翻阅。


The Transmission Control Protocol (TCP) is intended for use as a highly reliable host-to-host protocol between hosts in packet-switched computer communication networks, and in interconnected systems of such networks.

TCP is a connection-oriented, end-to-end reliable protocol designed to  fit into a layered hierarchy of protocols which support multi-network  applications.  The TCP provides for reliable inter-process  communication between pairs of processes in host computers attached to  distinct but interconnected computer communication networks.  Very few  assumptions are made as to the reliability of the communication  protocols below the TCP layer.  TCP assumes it can obtain a simple,  potentially unreliable datagram service from the lower level  protocols.  In principle, the TCP should be able to operate above a  wide spectrum of communication systems ranging from hard-wired  connections to packet-switched or circuit-switched networks.

TCP下层的服务可能是多样不可靠的

The primary purpose of the TCP is to provide reliable,  securable logical circuit or connection service between pairs of  processes.  

TCP的主要目的是:在不可靠的网络上为通讯双方提供可靠安全的逻辑链路。需要提供以下的逻辑

To provide this service on top of a less reliable internet  communication system requires facilities in the following areas:    

Basic Data Transfer    基本数据传输

Reliability    可靠性

Flow Control    流量控制

Multiplexing   多路复用

Connections    连接

Precedence and Security 优先级和安全性


Basic Data Transfer:    

The TCP is able to transfer a continuous stream of octets in each  direction between its users by packaging some number of octets into  segments for transmission through the internet system.  In general,    the TCPs decide when to block and forward data at their own    convenience.    Sometimes users need to be sure that all the data they have   submitted to the TCP has been transmitted.  For this purpose a push    function is defined.  To assure that data submitted to a TCP is    actually transmitted the sending user indicates that it should be    pushed through to the receiving user.  A push causes the TCPs to    promptly forward and deliver data up to that point to the receiver.    The exact push point might not be visible to the receiving user and    the push function does not supply a record boundary marker.

连接是双向通信的;字节流;字节封装成包;TCP自己决定何时停止和发送数据,如果需要确保已经提交的数据及时发送,可以使用push功能;


Reliability:    

The TCP must recover from data that is damaged, lost, duplicated, or delivered out of order by the internet communication system.  This is achieved by assigning a sequence number to each octet transmitted, and requiring a positive acknowledgment (ACK) from the  receiving TCP. If the ACK is not received within a timeout    interval, the data is retransmitted.  At the receiver, the sequence    numbers are used to correctly order segments that may be received    out of order and to eliminate duplicates.  Damage is handled by    adding a checksum to each segment transmitted, checking it at the    receiver, and discarding damaged segments.    As long as the TCPs continue to function properly and the internet    system does not become completely partitioned, no transmission    errors will affect the correct delivery of data.  TCP recovers from    internet communication system errors.  

TCP必须可以恢复以下数据:受损的、丢失的、重复的、乱序的;

每个字节一个编号,接受者确认,如果确认超时未收到应该重发;接收者根据编号来排序错序的报文和去除重复的报文。

受损的数据可以通过报文段的校验码来控制,丢弃受损的数据;

超时重发;


Flow Control:    

TCP provides a means for the receiver to govern the amount of data    sent by the sender.  This is achieved by returning a "window" with    every ACK indicating a range of acceptable sequence numbers beyond    the last segment successfully received.  The window indicates an    allowed number of octets that the sender may transmit before    receiving further permission.

流量控制,接收者控制发送者数据发送;窗口机制,每一个ACK报文段返回一个窗口值,当前确认的字节以后最多能发送的字节数;


Multiplexing:  

To allow for many processes within a single Host to use TCP  communication facilities simultaneously, the TCP provides a set of  addresses or ports within each host.  Concatenated with the network  and host addresses from the internet communication layer, this forms  a socket.  A pair of sockets uniquely identifies each connection.  That is, a socket may be simultaneously used in multiple  connections.  The binding of ports to processes is handled independently by each  Host.  However, it proves useful to attach frequently used processes  (e.g., a "logger" or timesharing service) to fixed sockets which are  made known to the public.  These services can then be accessed  through the known addresses.  Establishing and learning the port  addresses of other processes may involve more dynamic mechanisms

多路复用,同一个机器上可以存在多个TCP连接;端口+host=socket;两个socket确认一个连接;常用服务特定的端口号;


Connections:  

The reliability and flow control mechanisms described above require  that TCPs initialize and maintain certain status information for  each data stream.  The combination of this information, including  sockets, sequence numbers, and window sizes, is called a connection.  Each connection is uniquely specified by a pair of sockets  identifying its two sides.  When two processes wish to communicate, their TCP’s must first  establish a connection (initialize the status information on each  side).  When their communication is complete, the connection is  terminated or closed to free the resources for other uses.  Since connections must be established between unreliable hosts and  over the unreliable internet communication system, a handshake  mechanism with clock-based sequence numbers is used to avoid  erroneous initialization of connections.

连接:一些信息的组合,sockets+序列号+窗口;建立连接(初始化通信双方的状态信息),创建TCB(Transmission Control Block);

建立连接三次握手


Precedence and Security:  

The users of TCP may indicate the security and precedence of their  communication.  Provision is made for default values to be used when  these features are not needed.


0 0
原创粉丝点击