[读书笔记]网络协议 —————— TCP/IP

原创 2006年06月08日 13:04:00

---------------------------------- IP ----------------------------------

IP protocol:

IP is the workhorse protocol of the TCP/IP protocol suite.  All TCP, UDP, ICMP and IGMP data gets transmitted as IP datagrams.  IP provideds an unreliable, connectionless datagram delivery service.

By unreliable we mean there are no guarantees that an IP datagram successfully gets to its destination.  IP provides a best effort service.  When something goes wrong, such as a router temporarily running out of buffers, IP has a simple error handling algorithm: throw away the datagram and try to send an ICMP message back to the source.  Any required reliability must be provided by the upper layers(e.g. TCP).

The term connectionless means that IP does not maintain any state information about grams.  This also means that IP datagrams can get delivered out of order.  If a source sends two consecutive datagrams(first A, then B) to the same destination, each is routed independently and can take different routes, with B arriving before A.


IP Routing

Host routing can be simple: the destination is either on a directly connected network, in which case the datagram is sent derectly to the destination, or a default router is chosen.

Hosts and routers have a routing table that is used for all routing decisions.  There are three types of routes in the table: host specific, network specific, and optional default routes.  There is a priority to the entries in a routing table.  A host route will be chosen over a network router, and a default route is used only when no other route exists to the destination. 

IP routing is done on a hop-by-hop basis.  The destination IP address never changes as the datagram proceeds through all the hops, but the encapsulation and destination link-layer address can change on each hop.  Most hosts and many routers use a default next-hop router for all nonlocal traffic. 

---------------------------------- TCP ----------------------------------

Even though TCP and UDP use the same network layer (IP), TCP provides a totally different service to the application layer than UDP does.  TCP provides a connection-oriented, reliable, byte stream service.

The term connection-oriented means the two applications using TCP (normally considered a client and a server) must establish a TCP connation with each other before they can exchange data.  The typical analogy is dialing a telephone number, waiting for the other party to answer the phone and say “hello,” and then saying who’s calling. 


TCP provides reliability by doing the following:

Ø         The application data is broken into what TCP considers the best sized chunks to send.  This is totally different from UDP, where each write by the application generates a UDP datagram of that size.  The unit of information passed by TCP to IP is called a segment.

Ø         When TCP sends a segment it maintains a timer, waiting for the other end to acknowledge reception of the segment.  If an acknowledgment isn’t received in time, the segment is retransmitted.

Ø         When TCP receives data from the other end of the connection, it sends an acknowledgment.  This acknowledgment is not sent immediately, but normally delayed a fraction of a second.

Ø         TCP maintains a checksum on its header and data.  This is an end-to-end checksum whose purpose is to detect any modification of the data in transit.  If a segment arrives with an invalid checksum, TCP discards it and doesn’t acknowledgment receiving it. (It expects the sender to time our and retransmit.)

Ø         Since TCP segments are transmitted as IP datagrams, and since IP datagrams can arrive out of order, TCP segments can arrive out of order.  A receiving TCP resequences the data if necessary, passing the received data in correct order to the application.

Ø         Since IP datagrams can get duplicated, a receiving TCP must discard duplicate data.

Ø         TCP also provides flow control.  Each end of a TCP connection has a finite amount of buffer space.  A receiving TCP only allows the other end to send as much data as the receiver has buffers for.  This prevents a fast host from taking all the buffers on a slower host.


A stream of 8-bit bytes is exchanged across the TCP connection between the two applications.  There are no record markers automatically inserted by TCP.  This is what we called a byte stream service.  If the application on one end writes 10 bytes, followed by a write of 20 bytes, followed by a write of 50 bytes, the application at the other end of the connection cannot tell what size the individual writes were.  The other end may read the 80 bytes in four reads of 20 bytes at a time.  One end puts a stream of bytes into TCP and the same, identical stream of bytes appears at the other end.

Also, TCP does not interpret the contents of the bytes at all.  TCP has no idea if the data bytes being exchanged are binary data, ASCII characters, EBCDIC characters, or whatever.  The interpretation of this byte stream is up to the applications on each end of the connection.


TCP provides a reliable, connection-oriented, byte stream, transport layer service.  TCP packetizes the user data into segments, sets a timeout any time it sends data, acknowledges data received by the other end, reorders out-of-order data, discards duplicate data, provides end-to-end flow control, and calculates and verifies a mandatory end-to-end checksum.

TCP is used by many of the popular applications, such as Telnet, Rlogin, FTP, and electronic mail (SMTP).





网络协议和网络编程例程 常用的网络编程---TCP/IP协议编程 1.几个重要概念: (1). 端口(Port)和套接口 端口正是我们要扫描的对象,具有“开”和“关”两种状态,利用它的开或关状...

tcp/ip详解卷1:协议 读书笔记 IP网络层

一、TCP、UDP、ICMP、IGMP数据都使用IP数据报格式传输,所以IP是TCP/IP协议族中最为核心的协议。   二、IP提供不可靠、无连接的数据报传输服务; 1)不可靠的意思是不能保证I...


IP:网际协议 IP是TCP/IP协议族中最为核心的协议,提供一种不可靠、无连接的数据报传送服务。所谓的不可靠指的是它不能保证IP数据报能成功地到达目的地。无连接是说IP并不维护任何关于后续数据...


以太网是一种局域网技术,以下是以太网的各种专业名字术语解析: 1、  各种网络缩写含义:10Base-5,第一个数字表示传输的速率,以Mpbs为单位,base表示基带,及最后一个数字表示传输距离,基...


ARP:地址解析协议 当一台主机把以太网数据帧发送到位于同一局域网上的另一台主机时,是根据 48 bit的以太网地址来确定目的接口的。设备驱动程序从不检查IP数据报中的目的I P地址。地址解析为...


ICMP--Internet控制报文协议 ICMP被用来传递差错报文以及其他需要注意的信息,被认为是IP层的一个组成部分,通常被IP层或更高层协议使用,用来把差错报文返回给用回进程。其格式如下:...

TCP/IP详解卷1 读书笔记:第六章 ICMP 网际报文控制协议

引言 ICMP是IP网络中的信令兵,查询和通报网络中的错误及异常等。I C M P报文通常被 I P层或更高层协议(T C P或U D P)使用。一些 I C M P报文把差错报文返回给用户进程,如P...
  • wwww4
  • wwww4
  • 2015-10-02 12:26
  • 600

TCP/IP详解卷1 读书笔记:第二十八章 SMTP和POP3协议

SMTP,发件,25号端口。POP3,收件,110号端口。   SMTP协议 --- 发件   先找别名,再根据别名查IP,然后发邮件。                ...
  • wwww4
  • wwww4
  • 2015-12-13 21:15
  • 485

《TCP/IP详解 卷1:协议》读书笔记

一  前言 每当这个时候,最好的方法就是找一本书,然后用这本书来麻痹自己.其它乱七八糟的,都滚远点吧. 哈哈,屡试不爽! 开始抄书了..... 二  链路层 链路层作用 (1)...

TCP/IP详解卷1 读书笔记:第二十七章 FTP协议

FTP是数据传输主流协议。 它采用两个信道(两个TCP连接)进行传输。 第一信道,控制信道,无论何时都是由客户端发起连接。采用客户端服务器模式。服务端监听21端口。用于控制命令的传输。 第二信道...
  • wwww4
  • wwww4
  • 2015-12-13 20:51
  • 567