http://www.tcpipguide.com/free/t_TCPConnectionEstablishmentProcessTheThreeWayHandsh-3.htm

synchronous for SYN

Acknowledgement for ACK

第一次

第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SENT状态,等待服务器确认;SYN:同步序列编号(Synchronize Sequence Numbers)。
第二次

第二次握手:服务器收到syn包,必须确认客户的SYN(ack=j+1),同时自己也发送一个SYN包(syn=k),即SYN+ACK包,此时服务器进入SYN_RECV状态;
第三次

第三次握手:客户端收到服务器的SYN+ACK包,向服务器发送确认包ACK(ack=k+1),此包发送完毕,客户端和服务器进入ESTABLISHED(TCP连接成功)状态,完成三次握手。

上图的流程:服务端为192.168.1.18,客户的端为192.168.1.139

192.168.1.139首先向192.168.1.18发送syn包,包序号seq1为0

192.168.1.18收到192.168.1.139syn包后,将包序号加1,赋值给ack1。 ack1=seq1+1=1。同时还要发送自己的包序号seq2=0。

192.168.1.139收到回复之后,需要回复192.168.1.18。自己的包序号seq1=seq1+1=0+1=1。同时将服务端的包序号加1,再发送回去。即ack2=seq2+1=0+1=1

To establish a connection, each device must send a SYN and receive an ACK for it from the other device.

Thus, conceptually, we need to have four control messages pass between the devices.

However, it's inefficient to send a SYN and anACK in separate messages when one could communicate both simultaneously.

Thus, in the normal sequence of events in connection establishment, one of the SYNs and one of the ACKs is sent together by setting both of the relevant bits (a message sometimes called a SYN+ACK).

This makes a total of three messages, and for this reason the connection procedure is called a three-way handshake.

Key Concept: The normal process of establishing a connection between a TCP client and server involves three steps:

the client sends a SYN message;

the server sends a message that combines an ACK for the client’s SYN and contains the server’s SYN;

and then the client sends an ACK for the server’s SYN. This is called the TCP three-way handshake.

Table 152 describes in detail how the three-way handshake works (including a summary of the preparation discussed in the previous topic).

It is adapted from the table describing the TCP finite state machine, but shows what happens for both the server and the client over time.

Each row shows the state the device begins in, what action it takes in that state and the state to which it transitions.

The transmit and receive parts of each of the three steps of the handshake process are shown in the table, as well as in Figure 211.

Table 152: TCP “Three-Way Handshake” Connection Establishment Procedure

Client

Server

Start State

Action

Move To State

Start State

Action

Move To State

CLOSED

The client cannot do anything until the server has performed a passive OPEN and is ready to accept a connection. (Well, it can try, but nothing will be accomplished until the server is ready.)

CLOSED

The server performs a passive OPEN, creating a transmission control block (TCB) for the connection and readying itself for the receipt of a connection request (SYN) from a client.

LISTEN

CLOSED

Step #1 Transmit: The client performs an active OPEN, creating a transmission control block (TCB) for the connection and sending a SYN message to the server.

SYN-SENT

LISTEN

The server waits for contact from a client.

SYN-SENT

The client waits to receive an ACK to the SYN it has sent, as well as the server's SYN.

LISTEN

Step #1 Receive, Step #2 Transmit: The server receives the SYN from the client. It sends a single SYN+ACK message back to the client that contains an ACK for the client's SYN, and the server's own SYN.

SYN-RECEIVED

SYN-SENT

Step #2 Receive, Step #3 Transmit: The client receives from the server the SYN+ACK containing the ACK to the client's SYN, and the SYN from the server. It sends the server an ACK for the server'sSYN. The client is now done with the connection establishment.

ESTABLISHED

SYN-RECEIVED

The server waits for an ACK to the SYN it sent previously.

ESTABLISHED

The client is waiting for the server to finish connection establishment so they can operate normally.

 

SYN-RECEIVED

Step #3 Receive: The server receives the ACK to its SYNand is now done with connection establishment.

ESTABLISHED

ESTABLISHED

The client is ready for normal data transfer operations.

 

ESTABLISHED

The server is ready for normal data transfer operations.

 

 

Figure 211: TCP “Three-Way Handshake” Connection Establishment Procedure

This diagram illustrates how a conventional connection is established between a client and server, showing the three messages sent during the process and how each device transitions from theCLOSED state through intermediate states until the session is ESTABLISHED.

tcp连接的3次握手的更多相关文章

  1. 为什么建立TCP连接需要三次握手,为什么断开TCP连接需要四次握手,TIME_WAIT状态的意义

    为什么建立TCP连接需要三次握手? 原因:为了应对网络中存在的延迟的重复数组的问题 例子: 假设client发起连接的连接请求报文段在网络中没有丢失,而是在某个网络节点长时间滞留了,导致延迟到达ser ...

  2. TCP连接的3次握手和4次挥手

    TCP连接的3次握手和4次挥手笔记 三次握手 TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确 ...

  3. 详解TCP连接的“三次握手”与“四次挥手”(上)

    一.TCP connection 客户端与服务器之间数据的发送和返回的过程当中需要创建一个叫TCP connection的东西: 由于TCP不存在连接的概念,只存在请求和响应,请求和响应都是数据包,它 ...

  4. 详解TCP连接的“三次握手”与“四次挥手”(下)

    上文链接: 详解TCP连接的"三次握手"与"四次挥手"(上) 四.TCP的四次挥手(Four-Way Wavehand) 0.前言 对于"三次握手&q ...

  5. tcp连接的三次握手

    为什么tcp连接需要三次握手才能建立连接 主要是为了初始化sequence number的初始值,通信的双方要互相通知双方的sequence number,这个要作为以后数据通信的序号,保证以后不会因 ...

  6. TCP连接的三次握手和四次解散过程

    客户端和服务器在使用TCP连接传输数据的过程中,需要经过三次握手建立连接和四次握手断开连接操作. 具体如下图所示 上图描述了TCP连接从建立到断开的详细过程,以下就其中的具体报文细节展开讨论. 在TC ...

  7. Tcp连接的七次握手浅析

    LINUX 查看tcp连接数及状态 # netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' TIME_WAIT 8 ...

  8. python网络编程--TCP连接的三次握手(三报文握手)与四次挥手

    一.TCP连接 运输连接有三个阶段: 连接建立.数据传送和连接释放. 在TCP连接建立过程中要解决以下三个问题: 1,要使每一方能够确知对方的存在. 2.要允许双方协商一些参数(如最大窗口之,是否使用 ...

  9. 为什么TCP连接需要三次握手分开需要四次握手?

    TCP的三次握手和四次断开TCP是一个面向连接的服务,面向连接的服务是电话系统服务模式的抽象,每一次完整的数据传输都必须经过建立连接,数据传输和终止连接3个过程,TCP建立连接的过程称为三次握手,下面 ...

随机推荐

  1. 斐波那契数 c 语言实现

    斐波那契数列,又称黄金数列,指的是这样一个数列:1.1.2.3.5.8.13.21.……在数学上,斐波纳契数列以如下被以递归的方法定义:F(1)=1,F(2)=1,F(n)=F(n-1)+F(n-2) ...

  2. 离线文档(DocSet)下载地址汇总

    我分享的百度网盘地址,官网下载慢:http://pan.baidu.com/s/1uOBYQ 名称 下载地址 更新时间 IOS 9.2 031-43202-A.dmg 20151209 OS X 10 ...

  3. CodeIgniter 框架---学习笔记

    1.输出sql语句:echo $this->db->last_query();

  4. 2016 Multi-University Training Contest 1 Necklace 环排+二分匹配

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5727 题意:由2*N颗宝石构成的环(阴阳宝石均为N颗且标号均从1~N) 之后给定M组 a,b;表示阳宝石a ...

  5. 关于EndNote X6工具文献管理以及参考文献生成的使用

    1 利用endnote下载参考文献 1.1在CNKI中查找文献,在前面打钩,这里显示已经选中两篇文献了。 然后选择导出文献——选择Endnote——导出并保存text文件 打开Endnote——imp ...

  6. SQL Server数据库备份(异机)

    简单的远程异机备份数据库功能,通过这个存储过程,讲远程其他机器上的数据库备份到本地.其主要原理为: 1.通过XP_CMDSHELL执行Windows命令,将本机的共享目录映射为远程机器的网络驱动器. ...

  7. RegisterClientScriptBlock CommandName 模块列 操作完成 提示

    this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Remind", "alert('获取成功!') ...

  8. JAVA中的各种 哈希码(HashCode) 与 equals方法在HIBERNATE的实际应用[转载]

    1.什么是哈希码(HashCode) 在Java中,哈希码代表对象的特征.例如对象 Java代码 String str1 = “aa”, str1.hashCode= 3104 String str2 ...

  9. Asp.Net MVC过滤器小试牛刀

    在上学期间学习的Asp.Net MVC,基本只是大概马马虎虎的了解,基本处于知其然而不知其所以然.现在到上班,接触到真实的项目,才发现还不够用,于是从最简单的过滤器开始学习.不得不说MVC的过滤器真是 ...

  10. 彻底卸载网易UU网游加速器的方法

    昨天跟朋友一起玩游戏,网速感觉不怎么好就下了一个免费的网易UU加速器来给对战平台加速,结果加速了以后网速更差,我晕,于是想卸载,可这个加速器口只有一个exe文件,不用安装,但在第一次加速时记得安装了一 ...