2013年6月2日

TCP/IP内三个等待时间

换了一个地方,一直没有时间处理这篇博客,其实相关内容早就完成快一个月了,先把这部分发出来,后续再跟进。

先简单说下:TCP/IP内三个等待时间分别为

FIN-WAIT:
FIN-WAIT-1 - represents waiting for a connection termination request
from the remote TCP, or an acknowledgment of the connection
termination request previously sent.
FIN-WAIT-2 - represents waiting for a connection termination request
from the remote TCP.

CLOSE-WAIT - represents waiting for a connection termination request
from the local user.

TIME-WAIT - represents waiting for enough time to pass to be sure
the remote TCP received the acknowledgment of its connection
termination request.

(TCP)Transmission Control Protocol 被设计成用来提供高可靠的端到端之间的基于分组交换网络的传输层协议。

TCP(传输控制协议)提供不同于由UDP提供的服务。首先,TCP提供客户与服务器之间的连接。TCP客户先与某个给定服务器建立一个连接,再跨该连接与那个服务器交换数据,然后终止这个连接。其次,TCP还提供了可靠性。当TCP向另一端发送数据时,它要求对端返回一个确认。再次,TCP提供流量控制。TCP总是告知对端在任何时刻它一次能够从对端接收多少字节的数据,这称为通告窗口。最后,TCP连接是全双工的。这意味着在一个给定的连接上应用可以在任何时刻在进出两个方向上既发送数据又接收数据。值得注意的是,这样TCP必须为每个数据流方向跟踪诸如序列号和通告窗口大小等状态信息。

Basic Data Transfer
Reliability
Flow Control
Multiplexing
Connections
Precedence and Security
The TCP is assumed to be a module in an operating system.  The users
access the TCP much like they would access the file system.  The TCP
may call on other operating system functions, for example, to manage
data structures.  The actual interface to the network is assumed to be
controlled by a device driver module.  The TCP does not call on the
network device driver directly, but rather calls on the internet
datagram protocol module which may in turn call on the device driver.
计成用来提供高可靠的端到端之间的基于分组交换网络的传输层协议。


+------+ +-----+ +-----+       +-----+
|Telnet| | FTP | |Voice|  ...  |     |  Application Level
+------+ +-----+ +-----+       +-----+
|   |         |             |
+-----+     +-----+       +-----+
| TCP |     | RTP |  ...  |     |  Host Level
+-----+     +-----+       +-----+
|           |             |
+-------------------------------+
|    Internet Protocol & ICMP   |  Gateway Level
+-------------------------------+
|
+---------------------------+
|   Local Network Protocol  |    Network Level
+---------------------------+Protocol Relationships

计成用来提供高可靠的端到端之间的基于分组

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Acknowledgment Number                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Data |           |U|A|P|R|S|F|                               |
| Offset| Reserved  |R|C|S|S|Y|I|            Window             |
|       |           |G|K|H|T|N|N|                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                             data                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
TCP Header FormatNote that one tick mark represents one bit position.



Source Port:  16 bits
The source port number.
Destination Port: 16 bitsThe destination port number.
Sequence Number:  32 bits
The sequence number of the first data octet in this segment (except
when SYN is present). If SYN is present the sequence number is the
initial sequence number (ISN) and the first data octet is ISN+1.
Acknowledgment Number: 32 bits
If the ACK control bit is set this field contains the value of the
next sequence number the sender of the segment is expecting to
receive. Once a connection is established this is always sent.
Data Offset: 4 bits
The number of 32 bit words in the TCP Header. This indicates where
the data begins. The TCP header (even one including options) is an
integral number of 32 bits long.
Reserved: 6 bits
Reserved for future use. Must be zero.
Control Bits: 6 bits (from left to right):
URG: Urgent Pointer field significant
ACK: Acknowledgment field significant
PSH: Push Function
RST: Reset the connection
SYN: Synchronize sequence numbers
FIN: No more data from sender
Window: 16 bits
The number of data octets beginning with the one indicated in the
acknowledgment field which the sender of this segment is willing to
accept.
Checksum: 16 bits
The checksum field is the 16 bit one's complement of the one's
complement sum of all 16 bit words in the header and text. If a
segment contains an odd number of header and text octets to be
checksummed, the last octet is padded on the right with zeros to
form a 16 bit word for checksum purposes. The pad is not
transmitted as part of the segment. While computing the checksum,
the checksum field itself is replaced with zeros.The checksum also covers a 96 bit pseudo header conceptually
prefixed to the TCP header.  This pseudo header contains the Source
Address, the Destination Address, the Protocol, and TCP length.
This gives the TCP protection against misrouted segments.  This
information is carried in the Internet Protocol and is transferred
across the TCP/Network interface in the arguments or results of
calls by the TCP on the IP.
+--------+--------+--------+--------+
| Source Address |
+--------+--------+--------+--------+
| Destination Address |
+--------+--------+--------+--------+
| zero | PTCL | TCP Length |
+--------+--------+--------+--------+
The TCP Length is the TCP header length plus the data length in
octets (this is not an explicitly transmitted quantity, but is
computed), and it does not count the 12 octets of the pseudo
header.
Urgent Pointer: 16 bits
This field communicates the current value of the urgent pointer as a
positive offset from the sequence number in this segment. The
urgent pointer points to the sequence number of the octet following
the urgent data. This field is only be interpreted in segments with
the URG control bit set.
Options: variable
Options may occupy space at the end of the TCP header and are a
multiple of 8 bits in length. All options are included in the
checksum. An option may begin on any octet boundary. There are two
cases for the format of an option:
Case 1: A single octet of option-kind.
Case 2: An octet of option-kind, an octet of option-length, and
the actual option-data octets.
The option-length counts the two octets of option-kind and
option-length as well as the option-data octets.
Note that the list of options may be shorter than the data offset
field might imply. The content of the header beyond the
End-of-Option option must be header padding (i.e., zero).A TCP must implement all options.
Currently defined options include (kind indicated in octal):
Kind Length Meaning
---- ------ -------
0 - End of option list.
1 - No-Operation.
2 4 Maximum Segment Size.

Specific Option Definitions
End of Option List
+--------+
|00000000|
+--------+
Kind=0
This option code indicates the end of the option list. This
might not coincide with the end of the TCP header according to
the Data Offset field. This is used at the end of all options,
not the end of each option, and need only be used if the end of
the options would not otherwise coincide with the end of the TCP
header.
No-Operation
+--------+
|00000001|
+--------+
Kind=1
This option code may be used between options, for example, to
align the beginning of a subsequent option on a word boundary.
There is no guarantee that senders will use this option, so
receivers must be prepared to process options even if they do
not begin on a word boundary.
Maximum Segment Size+--------+--------+---------+--------+ |00000010|00000100| max seg size | +--------+--------+---------+--------+ Kind=2 Length=4
Maximum Segment Size Option Data:  16 bits
If this option is present, then it communicates the maximum
receive segment size at the TCP which sends this segment.
This field must only be sent in the initial connection request
(i.e., in segments with the SYN control bit set). If this
option is not used, any segment size is allowed.
Padding: variableThe TCP header padding is used to ensure that the TCP header ends and data begins on a 32 bit boundary. The padding is composed of zeros.
A connection progresses through a series of states during its
lifetime.  The states are:  LISTEN, SYN-SENT, SYN-RECEIVED,
ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK,
TIME-WAIT, and the fictional state CLOSED.  CLOSED is fictional
because it represents the state when there is no TCB, and therefore,
no connection.  Briefly the meanings of the states are:
LISTEN - represents waiting for a connection request from any remote
TCP and port.
SYN-SENT - represents waiting for a matching connection request
after having sent a connection request.
SYN-RECEIVED - represents waiting for a confirming connection
request acknowledgment after having both received and sent a
connection request.
ESTABLISHED - represents an open connection, data received can be
delivered to the user. The normal state for the data transfer phase
of the connection.
FIN-WAIT-1 - represents waiting for a connection termination request
from the remote TCP, or an acknowledgment of the connection
termination request previously sent.
FIN-WAIT-2 - represents waiting for a connection termination request
from the remote TCP.
CLOSE-WAIT - represents waiting for a connection termination request
from the local user.
CLOSING - represents waiting for a connection termination request
acknowledgment from the remote TCP.LAST-ACK - represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
TIME-WAIT - represents waiting for enough time to pass to be sure
the remote TCP received the acknowledgment of its connection
termination request.CLOSED - represents no connection state at all.
A TCP connection progresses from one state to another in response to
events.  The events are the user calls, OPEN, SEND, RECEIVE, CLOSE,
ABORT, and STATUS; the incoming segments, particularly those
containing the SYN, ACK, RST and FIN flags; and timeouts.

An established connection is said to be  "half-open" if one of the
TCPs has closed or aborted the connection at its end without the
knowledge of the other, or if the two ends of the connection have
become desynchronized owing to a crash that resulted in loss of
memory.  Such connections will automatically become reset if an
attempt is made to send data in either direction.  However, half-open
connections are expected to be unusual, and the recovery procedure is
mildly involved.

If at site A the connection no longer exists, then an attempt by the
user at site B to send any data on it will result in the site B TCP
receiving a reset control message.  Such a message indicates to the
site B TCP that something is wrong, and it is expected to abort the
connection.

posted @ 2013-06-02 17:06 teof 阅读(701) 评论(0) 推荐(0) 编辑

2012年5月25日

Erlang——cowboy源码剖析

摘要: 到了这个时候才有时间开始写这篇文章,为了昨天的承诺,坚持。cowboy是一个application,是一个小巧快速的良好模块化的http server。其中良好的clean module使得我们可以扩展到多种网络协议之中,cowboy自带的有tcp和ssl,而也有一些人提供了smtp等的扩展。我打算在接下去的项目中以cowboy作为框架完成一个服务器端来为移动互联网提供服务。。。移动互联网的特性上一章有所涉及,在此就不多说了。cowboy的特点:1.代码少。2.速度快。3.模块化程度高,transport和protocol都可轻易替换。4.采用二进制语法实现http服务,更快更小。5.极易嵌入 阅读全文

posted @ 2012-05-25 03:26 teof 阅读(390) 评论(0) 推荐(0) 编辑

2012年5月24日

Erlang——hotwheels源码剖析

摘要: 整体构架:janus_app(supervisor, Pid_root)监工了以下四个:janus_transport_sup(实质为transport, supervisor, Client Instance Supervisor):每个TCP会话创建一个transport进程来处理对应客户端的请求。janus_topman_sup(实质为topman, worker, Topic Manager):通过topman(gen_server)模块创建多个pubsup模块(gen_server)进程来管理主题。janus_proxy_mapper_sup(实质为mapper,worker, Cl 阅读全文

posted @ 2012-05-24 01:51 teof 阅读(384) 评论(0) 推荐(0) 编辑

2010年9月19日

谈谈个人对SnmpSharpNet的实践经验

摘要: 本文的目的鉴于网上没有使用该开发包的详尽说明,我在这里就讲述一下自己的经验之谈。说明一下,我发现有些人很喜欢纠结于一些不太有意义的事而不花时间去钻研那些很难很有深度的问题。在这里我先声明我只谈论本人关于SnmpSharpNet开发包的实践经验。开发包的下载地址:http://sourceforge.net/projects/snmpsharpnet/;开发包的详细说明文档:http://www.d... 阅读全文

posted @ 2010-09-19 19:13 teof 阅读(2088) 评论(4) 推荐(0) 编辑

第一次开发软件个人总结

摘要: 项目背景该项目源自于实验室从政府所拉到的项目,所属软件类型为网管软件。 本项目的特点主要有: 1.项目时间短,需要在四个月之内完成从需求到交付的一切工作。 2.缺乏实际的测试平台,由于硬件设备等诸多方面的原因,软件的核心——监控部分得不到好的平台来测试,只能做一些模拟测试。 3.客户需求定义很不明确,经常随着时间的变化而更改(这点是从后来客户不断地变更之前已确定的需求中得知... 阅读全文

posted @ 2010-09-19 19:09 teof 阅读(1407) 评论(0) 推荐(1) 编辑

详解volatile在C++中的作用

摘要: volatile的介绍 volatile类似于大家所熟知的const也是一个类型修饰符。volatile是给编译器的指示来说明对它所修饰的对象不应该执行优化。volatile的作用就是用来进行多线程编程。在单线程中那就是只能起到限制编译器优化的作用。所以单线程的童鞋们就不用浪费精力看下面的了。没有volatile的结果 如果没有volatile,你将无法在多线程中并行使用到基本变量。下面举一个我开... 阅读全文

posted @ 2010-09-19 19:03 teof 阅读(10348) 评论(0) 推荐(1) 编辑

2010年8月15日

关于C#定时器的总结

摘要: 在C#里关于定时器类有3个:1. 定义在System.Windows.Forms里实现在用户定义的时间间隔引发事件的计时器。此计时器最宜用于 Windows 窗体应用程序中,并且必须在窗口中使用。命名空间:System.Windows.Forms程序集:System.Windows.Forms(在 system.windows.forms.dll 中)备注:Timer 用于以用户定义的事件间隔触发事件。Windows 计时器是为单线程环境设计的,其中,UI 线程用于执行处理。它要求用户代码有一个可用的 UI 消息泵,而且总是在同一个线程中操作,或者将调用封送到另一个线程。使用此计时器时,请使用 阅读全文

posted @ 2010-08-15 09:35 teof 阅读(842) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示