Three-Way Handshake

The following scenario occurs when a TCP connection is established:

  1. 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.
  2. 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).
  3. 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.
  4. 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.

  1. 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.
  2. 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.
  3. Sometime later, the application that received the end-of-file will close its socket. This causes its TCP to send a FIN.
  4. 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的更多相关文章

  1. TCP connection status

    A TCP connection progresses through a series of states during its lifetime. The following diagram il ...

  2. linux上TCP connection timeout的原因查找

    linux上TCP connection timeout的原因查找 好久没有写文章了, 今天解决了一个网络连接超时的问题, 记录以备查看. 最近在线上nginx经常出现输出connection tim ...

  3. 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 ...

  4. RabbitMQ问题解决:TCP connection succeeded but Erlang distribution failed

    说明 本来是要先把Hystrix 仪表盘更完的,但是出现了Turbine.Dashboard.RabbitMQ整合实现监控. 所以先在学RabbitMq的基本操作,在安装过程中出现了 E:\Rabbi ...

  5. tcp connection

    三次握手与四次挥手的原因 https://yq.aliyun.com/articles/7435?spm=5176.8091938.0.0.N4v33a linux里的backlog详解 tcp co ...

  6. Exception in thread "RMI TCP Connection(idle)" java.lang.OutOfMemoryError: PermGen space

    在Eclipse 调试 springside showcase项目中,tomcat报异常 Exception in thread "RMI TCP Connection(idle)" ...

  7. 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 ...

  8. A TCP connection is distinguished by four values

    4个值唯一地定义一条TCP连接. HTTP The Definitive Guide A computer might have several TCP connections open at any ...

  9. 严重 [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 ...

随机推荐

  1. Android Studio SDK Manager无法正常下载如何设置

    博客分类: Linux 零散小知识 Android那点事 AndroidStudioSDKManager  一方面在/etc/hosts中设置: #Google主页 203.208.46.146 ww ...

  2. json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

    注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不 ...

  3. 手把手教你Windows下Go语言的环境搭建

    1.想写GO语言首先得下载go语言的开发包 官方下载地址:https://code.google.com/p/go/downloads/list 我用的是Win7 64位的操作系统,截图如下: 2.把 ...

  4. 线性回顾-generalize issue

    Ein的平均,Eout的平均 用这个平均来justify linear regresssion能够用的很好 noise level 资料里有多少的杂讯 等一下要证明的事情 predictions + ...

  5. Linux下追踪函数调用,打印栈帧

    事情的起因是这样的,之前同事的代码有一个内存池出现了没有回收的情况.也就是是Pop出来的对象没有Push回去,情况很难复现,所以在Pop里的打印日志,跟踪是谁调用了它,我想在GDB调试里可以追踪调用的 ...

  6. Artificial Intelligence

    //**************************************BEST-FS ALRORITHM IN ARTIFICAL INTELLIGENCE***************** ...

  7. Linux 共享内存编程

    共享内存允许系统内两个或多个进程共享同一块内存空间,并且数据不用在客户进程和服务器进程间复制,因此共享内存是通信速度最快的一种IPC. 实现的机制简单描述如下:一个进程在系统中申请开辟了一块共享内存空 ...

  8. markdown2 在win10下无法预览解决方案

    今天升级完Win10发现心爱的markdownPad 2无法预览,显示the view has crashed! 按照官网的Q&A http://markdownpad.com/faq.htm ...

  9. 疯狂的表单-html5新增表单元素和属性

    疯狂的表单 2015/11/27 16:44:07 从三方面来介绍html5表单的新特性 表单结构更灵活 要提交数据的控件可以布局在form标签之外,看下面的代码,表单元素可以写到form元素之外,只 ...

  10. Bootstrap_排版_表格

    一.基础表格 <table class="table"> <thead> <tr> <th>表格标题</th> < ...