TCP Connection Establishment and Termination
Three-Way Handshake
The following scenario occurs when a TCP connection is established:
- The server must be prepared to accept an incoming connection. This is normally done by calling socket, bind, and listen and is called a passive open.
- The client issues an active open by calling connect. This causes the client TCP to send a "synchronize" (SYN) segment, which tells the server the client's initial sequence number for the data that the client will send on the connection. Normally, there is no data sent with the SYN; it just contains an IP header, a TCP header, and possible TCP options (which we will talk about shortly).
- The server must acknowledge (ACK) the client's SYN and the server must also send its own SYN containing the initial sequence number for the data that the server will send on the connection. The server sends its SYN and the ACK of the client's SYN in a single segment.
- The client must acknowledge the server's SYN.
The minimum number of packets required for this exchange is three; hence, this is called TCP's three-way handshake.
We show the client's initial sequence number as J and the server's initial sequence number as K. The acknowledgment number in an ACK is the next expected sequence number for the end sending the ACK. Since a SYN occupies one byte of the sequence number space, the acknowledgment number in the ACK of each SYN is the initial sequence number plus one. Similarly, the ACK of each FIN is the sequence number of the FIN plus one.
TCP Connection Termination
While it takes three segments to establish a connection, it takes four to terminate a connection.
- One application calls close first, and we say that this end performs the active close. This end's TCP sends a FIN segment, which means it is finished sending data.
- The other end that receives the FIN performs the passive close. The received FIN is acknowledged by TCP. The receipt of the FIN is also passed to the application as an end-of-file (after any data that may have already been queued for the application to receive), since the receipt of the FIN means the application will not receive any additional data on the connection.
- Sometime later, the application that received the end-of-file will close its socket. This causes its TCP to send a FIN.
- The TCP on the system that receives this final FIN (the end that did the active close) acknowledges the FIN.
Since a FIN and an ACK are required in each direction, four segments are normally required. We use the qualifier "normally" because in some scenarios, the FIN in Step 1 is sent with data. Also, the segments in Steps 2 and 3 are both from the end performing the passive close and could be combined into one segment.
A FIN occupies one byte of sequence number space just like a SYN. Therefore, the ACK of each FIN is the sequence number of the FIN plus one.
TCP Connection Establishment and Termination的更多相关文章
- TCP connection status
A TCP connection progresses through a series of states during its lifetime. The following diagram il ...
- linux上TCP connection timeout的原因查找
linux上TCP connection timeout的原因查找 好久没有写文章了, 今天解决了一个网络连接超时的问题, 记录以备查看. 最近在线上nginx经常出现输出connection tim ...
- RT:How HTTP use TCP connection
In HTTP/0.9 (not used anymore), each request uses a separate TCP connection, and the end of a respon ...
- RabbitMQ问题解决:TCP connection succeeded but Erlang distribution failed
说明 本来是要先把Hystrix 仪表盘更完的,但是出现了Turbine.Dashboard.RabbitMQ整合实现监控. 所以先在学RabbitMq的基本操作,在安装过程中出现了 E:\Rabbi ...
- tcp connection
三次握手与四次挥手的原因 https://yq.aliyun.com/articles/7435?spm=5176.8091938.0.0.N4v33a linux里的backlog详解 tcp co ...
- Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space
在Eclipse 调试 springside showcase项目中,tomcat报异常 Exception in thread "RMI TCP Connection(idle)" ...
- the age of the TCP connection TCP Slow Start
w防止网络过载和拥塞 HTTP The Definitive Guide The performance of TCP data transfer also depends on the age of ...
- A TCP connection is distinguished by four values
4个值唯一地定义一条TCP连接. HTTP The Definitive Guide A computer might have several TCP connections open at any ...
- 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:解决
严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal Contain ...
随机推荐
- SqlServer中的merge操作,相当地风骚
今天在一个存储过程中看见了merge这个关键字,第一个想法是,这个是配置管理中的概念吗,把相邻两次的更改合并到一起.后来在technet上搜索发现别有洞天,原来是另外一个sql关键字,t-sql的语法 ...
- What's DB2 模式?
近期负责一个银行方面的项目,需要用到DB2实现多数据库版本切换.初步接触DB2,对于它的管理工具(IBM DATA STUDIO)虽然与ORACLE\MSSQL大同小异,但还是有些东西不一样的.比如什 ...
- Unix时间戳 和 NSDate 的转换
一个时间戳字符串:NSString *timeStampStr = @"1441602721"; 转换成时间 double unixTimeStamp ...
- Sql Server内置函数实现MD5加密
实例 MD5加密“123456”: HashBytes('MD5','123456') 结果:0xE10ADC3949BA59ABBE56E057F20F883E (提示:看完最后,结果要进行转换.) ...
- Binary Tree Level Order Traversal 解题思路 ×
要求: 树的层级遍历 思路: 1.两个队列,q1 q2 ,root放到q1 2.q1首元素出列,判断是否有左右孩子,有的话,放入q2.(循环此步骤值得q1为空) 3.q1 = q2,重复2,直到q1为 ...
- php函数应用场景
截取文件后缀: $slen = strlen($suffix); substr($this->uri_string, -$slen) === $suffix 原理:截取倒数多少长度字符 判断多维 ...
- PHP实现简易的模板引擎
PHP实现简易的模板引擎 1.MVC简介 MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式(详情自己百度): 1. Mode ...
- [Linux]关机和重启命令
Linux中常用的关机和重新启动命令有shutdown.halt.reboot以及init,它们都可以达到关机和重新启动的目的,但是每个命令的内部工作过程是不同的,下面将逐一进行介绍. 1. shu ...
- 使用pyinstaller 2.1将python打包并添加版本信息和图标
最近用 wxpython写了一个小的脚本,因为想要发布给没有装python和wxpython的人使用,遂决定使用pyinstaller 2.1进行打包. 其中遇到几个问题: 1,给打包的文件添加图标 ...
- 【转】Spring注解@Component、@Repository、@Service、@Controller区别
http://blog.csdn.net/zhang854429783/article/details/6785574 很长时间没做web项目都把以前学的那点框架知识忘光了,今天把以前做的一个项目翻出 ...