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 ...
随机推荐
- SQL输出矩阵
数据库环境:SQL SERVER2008R2 需求:用SQL实现如下2个图中的矩阵. 图1和图2都是行列转换的另一个变形,下面直接贴上SQL脚本. 图1的SQL实现 /*利用系统 ...
- Android 点击事件,4种回调。
1. 继承监听接口. 2. xml方式 : 设置 android:onClick 3. 内部类 4. 匿名类 ------------------------------------------- ...
- 查看xcode的路径
sudo /usr/libexec/locate.updatedb locate liblaunch_sim
- ios&h5混合开发项目仿app页面跳转优化
前言:本人原本是ios开发工程师,但由于现今H5的兴起,行内刮起了一阵混合开发的风气,趁着这股劲,我也学了前端开发,不说研究的多深,但也能胜任日常的开发工作.长话短说,现今的混合开发应该还处于摸索阶段 ...
- Python传参数最简单易懂的描述
关于,python的传参,很多人会搞得一头雾水,我也跟朋友讨论多次,最终通过实验,得到结论. 一.所有传递都是引用传递 二.在函数内使用[变量名]=,相当于定义啦一个局部变量 OK,一段简单的 ...
- 关于MVC中使用dynamic
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2kAAAB6CAIAAACqQIxZAAAgAElEQVR4nO2dT2wcx53v6zgXAgsYvA
- wordpress4.0.1源码学习和摘录--函数
1.根据类型获取当前时间 function current_time( $type, $gmt = 0 ) { switch ( $type ) { case 'mysql': return ( $g ...
- C#快递单号查询源码
源码本人测试过,没有啥问题,能查询快递单号,支持的快递还挺多,圆通快递.申通快递.韵达快递的都支持单号查询的,程序是通过向爱快递(www.aikuaidi.cn)接口传输参数来查询快递单号,我直接把代 ...
- linux之GDB常用命令汇总
查看gdb的版本号 (1)rpm -q gdb 会显示是否安装gdb及版本号 (2)gdb --version也可以 breakpoint b main; b 20; 设置断点 breakpoint ...
- 简单学C——第七天
函数 函数是C语言重要的组成部分,你现在,或者以后(如果C没什么变化的话)所写的任何一个C语言程序都是由一个一个的函数组合在一起的,当然,现在或许你只会在主函数 main中写一个小程序,那么在看了本篇 ...