网络连接状态

上传人:re****.1 文档编号:564835318 上传时间:2022-11-03 格式:DOCX 页数:6 大小:76.18KB
返回 下载 相关 举报
网络连接状态_第1页
第1页 / 共6页
网络连接状态_第2页
第2页 / 共6页
网络连接状态_第3页
第3页 / 共6页
网络连接状态_第4页
第4页 / 共6页
网络连接状态_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《网络连接状态》由会员分享,可在线阅读,更多相关《网络连接状态(6页珍藏版)》请在金锄头文库上搜索。

1、clientsocket ccDncct fbkxki) (aeijvc epenj SYN SENT竺込阴碍士输serversccXt. bind, listen LISTFN yiMYL”l JGTCpt i.Wtk6j7 sYN.kcvn一、Linux服务器上11种网络连接状态:Figure 2.5 Packet exchange for TCP connection.read rtBlnnVirelive dew) HX_WAI1_I-J:V -四初挥手心CI-OSL_VVAI 1 pivccl(w) read rttunis dESTABIISHBI3L?Dai.LCCL EllLi

2、nlFh*畑UM ArrcLoseLA5l_At:KCLOSED图:TCP的状态机通常情况下:一个正常的TCP连接,都会有三个阶段:1、TCP三次握手;2、数据 传送;3、TCP四次挥手注:以下说明最好能结合”图:TCP的状态机”来理解。SYN:(同步序列编号Synchronize Sequence Numbers)该标志仅在三次握手建立 TCP 连接时有效。表示一个新的 TCP 连接请求。ACK:(确认编号,Acknowledgement Number)是对TCP请求的确认标志,同时提示 对端系统已经成功接收所有数据。FIN:(结束标志,FINish)用来结束一个TCP回话但对应端口仍处于开

3、放状态, 准备接收后续数据。1)、LISTEN:首先服务端需要打开一个socket进行监听,状态为LISTEN. /* The socket is listening for incoming connections.侦听来自远方 TCP 端口的连 接请求 */2)、SYN_SENT:客户端通过应用程序调用connect进行active open.于是客户端tcp 发送一个 SYN 以请求建立一个连接.之后状态置为 SYN_SENT. /*The socket is actively attempting to establish a connection. 在发送连接请求后等待 匹配的连接请

4、求 */3)、SYN_RECV:服务端应发出ACK确认客户端的SYN,同时自己向客户端发送一个 SYN. 之后状态置为 SYN_RECV /* A connection request has been received from the network. 在收到和发送一个连接请求后等待对连接请求的确认 */4)、 ESTABLISHED: 代表一个打开的连接,双方可以进行或已经在数据交互了。 /* The socket has an established connection. 代表一个打开的连接,数据 可以传送给用户 */5)、FIN_WAIT1:主动关闭(active close)端应

5、用程序调用close,于是其TCP发 出FIN请求主动关闭连接,之后进入FIN_WAIT1状态./* The socket is closed, and the connection is shutting down. 等待远程 TCP 的连接中断请求,或先 前的连接中断请求的确认 */6)、CLOSE_WAIT:被动关闭(passive close)端TCP接到FIN后,就发出ACK以回 应 FIN 请求(它的 接收也作 为文件结束符传递给 上层应用 程序 ), 并进入 CLOSE_WAIT./* The remote end has shut down, waiting for the s

6、ocket to close. 等待从本地用户发来的连接中断请求 */7)、FIN_WAIT2:主动关闭端接到 ACK 后,就进入了 FIN-WAIT-2 ./* Connection is closed, and the socket is waiting for a shutdown from the remote end. 从远程 TCP 等待连接中断请求 */8)、LAST_ACK:被动关闭端一段时间后,接收到文件结束符的应用程序将调用 CLOSE 关闭连接。这导致它的 TCP 也发送一个 FIN, 等待对方的 ACK. 就进入了 LAST-ACK . /* The remote en

7、d has shut down, and the socket is closed. Waiting for acknowledgement. 等待原来发向远程 TCP 的连接中断请求的确认 */9)、TIME_WAIT:在主动关闭端接收到FIN后,TCP就发送ACK包,并进入TIME-WAIT 状态。/* The socket is waiting after close to handle packets still in the net work.等待足够的时间以确保远程TCP接收到连接中断请求的确认*/10)、CLOSING: 比较少见. /* Both sockets are shu

8、t down but we still dont have all our data sent. 等待远程 TCP 对连接中断的确认 */11)、CLOSED:被动关闭端在接受到ACK包后,就进入了 closed的状态。连接结 束./* The socket is not being used. 没有任何连接状态 */TIME_WAIT 状态的形成只发生在主动关闭连接的一方。主动关闭方在接收到被动关闭方的FIN请求后,发送成功给对方一个ACK后,将 自己的状态由FIN_WAIT2修改为TIME_WAIT,而必须再等2倍 的MSL(Maximum Segment Lifetime,MSL 是一个

9、数据报在 internetwork 中能存在的时间)时间之 后双方才能把状态 都改为CLOSED以关闭连接。目前RHEL里保持TIME_WAIT状 态的时间为 60 秒。当然上述很多TCP状态在系统里都有对应的解释或设置,可见man tcp 二、关于长连接和短连接:通俗点讲:短连接就是一次TCP请求得到结果后,连接马上结束.而长连接并不马 上断开,而一直保持着,直到长连接TIMEOUT(具体程序都有相关参数说明).长连 接可以避免不断的进行TCP三次握手和四次挥手.长连接(keepalive)是需要靠双方不断的发送探测包来维持的,keepalive期间 服务端和客户端的TCP连接状态是ESTA

10、BLISHED.目前http 1.1版本里默认都是 keepalive(1.0版本默认是不keepalive的),ie6/7/8和firefox都默认用的是 http 1.1 版本了(如何查看当前浏览器用的是哪个版本,这里不再赘述)。Apache,java 一个应用至于到底是该使用短连接还是长连接,应该视具体情况而定。一般的应 用应该使用长连接。1、Linux 的相关 keepalive 参数a、tcp_keepalive_time - INTEGERHow often TCP sends out keepalive messages when keepalive is enabled.Def

11、ault: 2hours.b、tcp_keepalive_probes - INTEGERHow many keepalive probes TCP sends out, until it decides that the connection is broken. Default value:9.c、tcp_keepalive_intvl - INTEGERHow frequently the probes are send out. Multiplied bytcp_keepalive_probes it is time to kill not responding connection,

12、 after probes started. Default value: 75sec i.e. connection will be aborted after 11 minutes of retries.2、F5负载均衡上的相关参数说明a、Keep Alive IntervalSpecifies, when enabled, how frequently the system sends data over an idle TCP connection, to determine whether the connection is still valid.Specify: Specifie

13、s the interval at which the system sends data over an idle connection, to determine whether the connection is still valid. The default is 1800 milliseconds.b、Time WaitSpecifies the length of time that a TCP connection remains in the TI-WEAIT state before entering the CLOSED state.Specify: Specifies

14、the number of milliseconds that a TCP connection can remain in the TIME-WAIT state. The default is 2000.c、Idle TimeoutSpecifies the length of time that a connection is idle (has no traffic) before the connection is eligible for deletion.Specify: Specifies a number of seconds that the TCP connection

15、can remain idle before the system deletes it. The default is300 seconds.3、Apache的相关参数说明以下是Apache/2.0.61版本的默认参数和说明a、KeepAlive:default On.Whether or not to allow persistent connections (more than one request per connection). Set to “Off” to deactivate.b、MaxKeepAliveRequests:default 100.The maximum number of requests to allow during a persistent connection. Set to0 to allow an unlimited amount. We recommend you leave this number high, for maximum performance.c、KeepAliveTimeout:default 15. Number of seconds to wait for the next

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号