tcp/ip 只有四次挥手?还有三次挥手

【Linux网络】TCP/IP三次握手、四次挥手流程 本文重点讲述了TCP/IP 的三次握手和四次挥手的过程,还讲述的主要字段,如:标志位,序号,确认序号等。三次握手和四次挥手的报文变化,最后给了几个常考的面试题。 阅读详情

在这里插入图片描述
我们经常说tcp/ip 三次握手与四次挥手,实时上tcp/ip并不总是这样,它会存在一些特殊情况,并对这些特殊情况作了优化,下面给大家演示一遍:

抓取我的服务器地址8080端口的一次http请求 ,在服务器端执行命令,抓取8080端口的请求:

tcpdump -S -i eth0   tcp port 8080
在客户端请求url地址

wget  http://118.24.47.200:8080/jvm/getJVMList.json

抓取到的数据包如下:

00:05:30.076277 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [S], seq 3495051296, win 14600, options [mss 1424,sackOK,TS val 1695780977 ecr 0,nop,wscale 7], length 0
00:05:30.076294 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [S.], seq 485492531, ack 3495051297, win 28960, options [mss 1460,sackOK,TS val 629900081 ecr 1695780977,nop,wscale 7], length 0
00:05:30.115447 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492532, win 115, options [nop,nop,TS val 1695781016 ecr 629900081], length 0
00:05:30.115916 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [P.], seq 3495051297:3495051432, ack 485492532, win 115, options [nop,nop,TS val 1695781017 ecr 629900081], length 135
00:05:30.115924 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [.], ack 3495051432, win 235, options [nop,nop,TS val 629900120 ecr 1695781017], length 0
00:05:30.117071 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [P.], seq 485492532:485492629, ack 3495051432, win 235, options [nop,nop,TS val 629900122 ecr 1695781017], length 97
00:05:30.156220 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492629, win 115, options [nop,nop,TS val 1695781057 ecr 629900122], length 0
00:05:30.157325 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [F.], seq 3495051432, ack 485492629, win 115, options [nop,nop,TS val 1695781058 ecr 629900122], length 0
00:05:30.157562 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [F.], seq 485492629, ack 3495051433, win 235, options [nop,nop,TS val 629900162 ecr 1695781058], length 0
00:05:30.196710 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492630, win 115, options [nop,nop,TS val 1695781097 ecr 629900162], length 0

解释上面的通信过程

#三次握手第一步 客户端发起连接请求    客户端初始序列号为 3495051296
#sin seq = 3495051296
00:05:30.076277 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [S], seq 3495051296, win 14600, options [mss 1424,sackOK,TS val 1695780977 ecr 0,nop,wscale 7], length 0
#三次握手第二步 服务端应答            服务器端初始序列号为 485492531
#sin seq = 485492531 ack = 3495051296 +1 = 3495051297
00:05:30.076294 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [S.], seq 485492531, ack 3495051297, win 28960, options [mss 1460,sackOK,TS val 629900081 ecr 1695780977,nop,wscale 7], length 0
#三次握手第三步 客户端应答           客户端序列号为 3495051297
#ack ack = 485492532 + 1
00:05:30.115447 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492532, win 115, options [nop,nop,TS val 1695781016 ecr 629900081], length 0
#客户端向服务器发送数据包            客户端序列号为 3495051432
#push seq = 3495051297:3495051432  数据包长度 length = 3495051432 - 3495051297 = 135
00:05:30.115916 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [P.], seq 3495051297:3495051432, ack 485492532, win 115, options [nop,nop,TS val 1695781017 ecr 629900081], length 135
#服务器端接收数据包应答              服务器端序列号为 485492532
#ack  = 3495051432
00:05:30.115924 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [.], ack 3495051432, win 235, options [nop,nop,TS val 629900120 ecr 1695781017], length 0
#服务器端返回响应内容数据包          服务器端序列号为 485492629 
#push seq = 485492532:485492629  数据包长度 length = 485492629 - 485492532 = 135  ack = 3495051432
00:05:30.117071 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [P.], seq 485492532:485492629, ack 3495051432, win 235, options [nop,nop,TS val 629900122 ecr 1695781017], length 97
#客户端接收数据包应答                客户端序列号为 3495051432
#ack = 485492629代表收到的包的序列号;
00:05:30.156220 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492629, win 115, options [nop,nop,TS val 1695781057 ecr 629900122], length 0
#三次挥手 -- 客户端发起断开连接请求    客户端序列号为 3495051432
#fin  seq = 3495051432
00:05:30.157325 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [F.], seq 3495051432, ack 485492629, win 115, options [nop,nop,TS val 1695781058 ecr 629900122], length 0
#三次挥手 -- 服务器端发起断开连接请求
#ack = 3495051432 + 1 = 3495051433  注意 因为服务器端也没有东西要发送了,所以也要关闭连接,因此同时发送了fin信号,seq = 485492629
00:05:30.157562 IP VM_0_6_centos.webcache > 221.122.42.100.58706: Flags [F.], seq 485492629, ack 3495051433, win 235, options [nop,nop,TS val 629900162 ecr 1695781058], length 0
#三次挥手 -- 客户端应答
#ack = 485492629 + 1 = 485492630 
00:05:30.196710 IP 221.122.42.100.58706 > VM_0_6_centos.webcache: Flags [.], ack 485492630, win 115, options [nop,nop,TS val 1695781097 ecr 629900162], length 0

看到这里有没有发现最后的挥手状态,并不是四次挥手,而是三次挥手???

这是因为关闭连接有两种方式,当一方关闭连接,另外一方没有数据发送时,马上关闭连接,也就将第二步的ack与第三步的fin合并为一步了,这个优化在RFC793 3.5节:

3.5. Closing a Connection
CLOSE is an operation meaning “I have no more data to send.” The notion of closing a full-duplex connection is subject to ambiguous interpretation, of course, since it may not be obvious how to treat the receiving side of the connection. We have chosen to treat CLOSE in a simplex fashion. The user who CLOSEs may continue to RECEIVE until he is told that the other side has CLOSED also. Thus, a program could initiate several SENDs followed by a CLOSE, and then continue to RECEIVE until signaled that a RECEIVE failed because the other side has CLOSED. We assume that the TCP will signal a user, even if no RECEIVEs are outstanding, that the other side has closed, so the user can terminate his side gracefully. A TCP will reliably deliver all buffers SENT before the connection was CLOSED so a user who expects no data in return need only wait to hear the connection was CLOSED successfully to know that all his data was received at the destination TCP. Users must keep reading connections they close for sending until the TCP says no more data. [Page 37]

                                                      September 1981

Transmission Control Protocol
Functional Specification

There are essentially three cases:

1) The user initiates by telling the TCP to CLOSE the connection

2) The remote TCP initiates by sending a FIN control signal

3) Both users CLOSE simultaneously

Case 1: Local user initiates the close

In this case, a FIN segment can be constructed and placed on the
outgoing segment queue.  No further SENDs from the user will be
accepted by the TCP, and it enters the FIN-WAIT-1 state.  RECEIVEs
are allowed in this state.  All segments preceding and including FIN
will be retransmitted until acknowledged.  When the other TCP has
both acknowledged the FIN and sent a FIN of its own, the first TCP
can ACK this FIN.  Note that a TCP receiving a FIN will ACK but not
send its own FIN until its user has CLOSED the connection also.

Case 2: TCP receives a FIN from the network

If an unsolicited FIN arrives from the network, the receiving TCP
can ACK it and tell the user that the connection is closing.  The
user will respond with a CLOSE, upon which the TCP can send a FIN to
the other TCP after sending any remaining data.  The TCP then waits
until its own FIN is acknowledged whereupon it deletes the
connection.  If an ACK is not forthcoming, after the user timeout
the connection is aborted and the user is told.

Case 3: both users close simultaneously

A simultaneous CLOSE by users at both ends of a connection causes
FIN segments to be exchanged.  When all segments preceding the FINs
have been processed and acknowledged, each TCP can ACK the FIN it
has received.  Both will, upon receiving these ACKs, delete the
connection.

[Page 38]

September 1981
Transmission Control Protocol
Functional Specification

  TCP A                                                TCP B
  1. ESTABLISHED ESTABLISHED

  2. (Close)
    FIN-WAIT-1 --> <SEQ=100><ACK=300><CTL=FIN,ACK> --> CLOSE-WAIT

  3. FIN-WAIT-2 <-- <SEQ=300><ACK=101><CTL=ACK> <-- CLOSE-WAIT

  4.                                                   (Close)
    

    TIME-WAIT <-- <SEQ=300><ACK=101><CTL=FIN,ACK> <-- LAST-ACK

  5. TIME-WAIT --> <SEQ=101><ACK=301><CTL=ACK> --> CLOSED

  6. (2 MSL)
    CLOSED

                   Normal Close Sequence
    
                         Figure 13.
    

    TCP A TCP B

  7. ESTABLISHED ESTABLISHED

  8. (Close) (Close)
    FIN-WAIT-1 --> <SEQ=100><ACK=300><CTL=FIN,ACK> … FIN-WAIT-1
    <-- <SEQ=300><ACK=100><CTL=FIN,ACK> <–
    … <SEQ=100><ACK=300><CTL=FIN,ACK> -->

  9. CLOSING --> <SEQ=101><ACK=301><CTL=ACK> … CLOSING
    <-- <SEQ=301><ACK=101><CTL=ACK> <–
    … <SEQ=101><ACK=301><CTL=ACK> -->

  10. TIME-WAIT TIME-WAIT
    (2 MSL) (2 MSL)
    CLOSED CLOSED

                Simultaneous Close Sequence
    

————————————————
版权声明:本文为优快云博主「朱清震」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/zqz_zqz/article/details/79548381

​TCP/IP协议三次握手和四次挥手 TCP/IP简介:TCP/IP 是不同的通信协议的大集合。是指能够在多个不同网络间实现信息传输的协议族。TCP/IP协议不仅仅指的是TCP 和IP两个协议,而是指一个由FTP、SMTP、TCP、UDP、IP等协议构成的协议族, 只是因为在TCP/IP协议中TCP协议和IP协议最具代表性,所以被称为TCP/IP协议。TCP/IP协议参考ISO,OSI模型共有七层,但在TCP/IP协议中,它们被简化为了四个层次。如图:三次握手建立连接三次握手(Three-way Handshake)其实就是指建立一个TCP连接 阅读详情

相关推荐

TCP/IP三次握手,四次挥手详解

第二次握手:服务端收到客户端建立连接的请求,发送自己的SYN报文作为应答,生成自己的序列号seq= y,把客户端的序列号加1作为自己ack的值,ack=x+1,此时服务端进入SYN-RCVD(接收到客户端的请求,.并响应客户端的请求,等待被确认)第三次握手:客户端收到同意的报文后,向服务端发送了一个确认报文,表示已经收到服务器端的同意连接的报文,把服务端的序列号加1作为ack 的值,发送完客户端进入ESTAB-LISHED状态。​ 这样服务端就能得出结论:客户端的发送能力、服务端的接收能力是正常的。

xtzhiker的博客 3613

TCP/IP协议中的四次挥手

首先,我们可以知道,如果双方想断开连接,那一定是双方都没有数据想发送给对方了,这时就存在着一个问题,我知道我自己没有数据发送了,但是我没有办法知道对方是否还有数据要发,所以我们可以将这多余的一次沟通看成是这个多余的步骤的补偿。2MSL,MSL表示信息传递过程中不会丢失的最大时间,之所以2MSL时间,是因为客户端需要确定服务器收到了我的确认信息。TCP/IP协议中有一个规定,如果对方没有收到我的信息,那么在2MSL时间后就会有一个超时重传命令,如果2MSL时间后没有收到任何命令,表示我也可以关闭连接了。

m0_60815231的博客 525

阿里面试官: HTTP、HTTPS、TCP/IP、Socket通信、三次握手四次挥手过程?(附全网最具深度的三次握手、四次挥手讲解)

前言 这段时间面试官都挺忙的,频频出现在博客文章标题,虽然我不是特别想蹭热度,但是实在想不到好的标题了-。-,蹭蹭就蹭蹭 ???? 事实上我在阿里面试的时候确实被问到了这个问题,HTTP、HTTPS、TCP/IP、Socket通信、三次握手四次挥手过程?当时虽然思路正确,可惜最终也并不算完全答对 结束后花了一段时间整理了下思路,参考和查阅了一下资料,整理如下: 来源:编程充电宝 作者:在所不辞 问题描述...

weixin_43901866的博客 1866

TCP/IP三次握手、四次挥手流程

TCP共有6个标志位,分别是: SYN(synchronous),建立联机。 ACK(acknowledgement),确认。 PSH(push),传输。 FIN(finish),结束。 RST(reset),重置。 URG(urgent),紧急。 TCP/IP三次握手 通俗: A与B建立TCP连接时: 1、首先A向B发SYN(同步请求), 2、然后B回复SYN+ACK(同...

猎人在吃肉 1万+

TCP/IP三次握手四次挥手

由于TCP连接是全双工的,因此,每个方向都必须要单独进行关闭,这一原则是当一方完成数据发送任务后,发送一个FIN来终止这一方向的连接,收到一个FIN只是意味着这一方向上没有数据流动了,即不会再收到数据了,但是在这个TCP连接上仍然能够发送数据,直到这一方向也发送了FIN。首先进行关闭的一方将执行主动关闭,而另一方则执行被动关闭。

qq_34341338的博客 2152

TCP/IP三次握手与四次挥手学习笔记

tcp的"三次握手"与"四次挥手"是tcp/ip的重点知识,一直不甚熟悉,网络上的资料也很多很杂,要么太繁,要么太简,所以在此学习总结以适应博主自身的情况,交流才能进步,望各路大神提出宝贵意见,共同进步!

Leeon的博客 5428

TCP 四次挥手,可以变成三次挥手吗?

当被动关闭方在 TCP 挥手过程中,如果「没有数据要发送」,同时「没有开启 TCP_QUICKACK(默认情况就是没有开启,没有开启 TCP_QUICKACK,等于就是在使用 TCP 延迟确认机制)」,那么第二和第三次挥手就会合并传输,这样就出现了三次挥手。所以,出现三次挥手现象,是因为 TCP 延迟确认机制导致的。完!......

小林coding 5888

基于COMSOL电弧动态仿真模型优化:高收敛性可修改吹弧方案解析

在多物理场耦合分析中,电弧动态仿真历来是数值稳定性的难点:温度从室温跃升至数万开尔文,电导率随温度呈数量级跳变,流动、传热与电磁场相互牵制,极易引发求解器不收敛或初始值不一致等问题。如何构建高收敛性的数值模型,成为开关设备灭弧性能优化的重要技术基础。通过合理的几何简化、全耦合求解器配置、辅助扫描初始化策略以及参数化建模手段,可以实现对吹弧方案的灵活调整与批量寻优,从而系统性评估气流速度、喷口形状、触头间距等关键因素对熄弧性能的影响。这类仿真方法广泛应用于断路器、接触器等高压电器产品研发,为灭弧室结构设计提供

weixin_29758911的博客 350

TCP三次握手为什么是三次,四次挥手为什么是四次!!!

第二次握手是服务器端接收到SYN(同步序列号请求)报文后,返回带有确认号ACK和SYN标志位的报文,表示接受建立连接请求。四次挥手之所以是四次,是因为在TCP中数据的传输是双向的,每一方都需要单独关闭连接,而且可能还存在未传输完的数据段和对方的ACK报文,因此需要四次握手来确保双方的连接被正确关闭。就类似于我和你见面,第一次我伸出手给你发出和你握手的信号,等待握手,第二次是你收到我的信号后,伸出了你的手,来接受和我握手,然后第三次我和你进行握手。

2201_75642447的博客 921

我用两种方式玩转 MCP:CherryStudio vs VS Code 实测手记

MCP,全称,你可以理解为——给大模型装上“手脚”和“工具箱”。传统大模型像一位博学但手不能动的学者:“我知道怎么算圆周率,但没法打开计算器。而支持 MCP 的模型,能通过标准协议自动调用外部工具(比如fetch网络请求、readFile读文件、shell执行命令),真正做到“知行合一”。输入后**,保存,**之后就显示出来了MCP 不是“魔法”,而是把 AI 从“问答机”升级为“智能代理”的关键一步。工具本身不难,难的是“知道它能解决什么问题”。

zyq569的博客 1020

Windows 11下用Ollama一键部署DeepSeek-R1大模型(附8B/14B版本选择建议)

本文详细介绍了在Windows 11环境下使用Ollama工具一键部署DeepSeek-R1大模型的完整指南,包括8B和14B版本的选择建议。通过硬件评估、安装配置、性能优化等步骤,帮助开发者高效实现本地部署,提升AI应用体验。

weixin_29079643的博客 272

TCP/IP四次挥手

第一次: 客户端发送一个FIN,用来关闭客户端到服务器的数据传送,客户端进入FIN_WAIT_1状态。 第二次: 服务器收到FIN后,发送一个ACK给客户端,确认序号为收到序号+1(与SYN相同,一个FIN占用一个序号),服务器进入CLOSE_WAIT状态。 第三次: 服务器发送一个FIN,用来关闭服务器到客户端的数据传送,服务器进入LAST_ACK状态。 第四次: 客户端收到FIN...

yang_china的博客 372

基于紫光展锐平台的音频调用到hal层逻辑

基于紫光展锐平台的音频调用到hal层逻辑 1、数据流程图 AudioPolicyService和AudioFlinger的创建: 这两个服务都在audioserver中启动,文件路径: frameworks/av/media/audioserver/main_audioserver.cpp 从AudioFlinger和AudioPolicyService的创建,到output的打开,以及AudioFlinger开始往底层写入数据的具体流程如下图: #mermaid-svg-kjHL4XWwkQXN6NdA

weixin_55053963的博客 1355

ack strom 保证只有一次_卧槽!牛皮了,头一次见有大佬把TCP/IP三次握手四次挥手解释的这么明白...

原文:https://blog.youkuaiyun.com/ThinkWo...计算机网络体系结构在计算机网络的基本概念中,分层次的体系结构是最基本的。计算机网络体系结构的抽象概念较多,在学习时要多思考。这些概念对后面的学习很有帮助。网络协议是什么?在计算机网络要做到有条不紊地交换数据,就必须遵守一些事先约定好的规则,比如交换数据的格式、是否需要发送一个应答信息。这些规则被称为网络协议。为什么要对网络协议分...

weixin_39773239的博客 148

【笔记】2022.6.7 数据分析概论

已完结

SpriteNym的博客 1372

全网首发:香橙派5MAX安装ubuntu20.04(换了官方桌面)及ros,运行LIVOX-mid360混合固态激光雷达,实际测试fastlio(只能说可以跑,还是有点吃力)

独家发布!!!香橙派5MAX安装ubuntu20.04(换了官方桌面)及ros,运行mid360混合固态激光雷达,测试fastlio(只能说可以跑,还是有点吃力),国货也算崛起了。

2402_82745259的博客 5995

ack strom 保证只有一次_卧槽!牛皮了,头一次见有大佬把TCP/IP三次握手四次挥手解释的这么明白&大厂易错面试题...

计算机网络体系结构在计算机网络的基本概念中,分层次的体系结构是最基本的。计算机网络体系结构的抽象概念较多,在学习时要多思考。这些概念对后面的学习很有帮助。网络协议是什么?在计算机网络要做到有条不紊地交换数据,就必须遵守一些事先约定好的规则,比如交换数据的格式、是否需要发送一个应答信息。这些规则被称为网络协议。为什么要对网络协议分层?简化问题难度和复杂度。由于各层之间独立,我们可以分割大问...

weixin_39963053的博客 80

【AI大模型】核心基石:Transformer架构入门通俗完整解读

文章摘要: Transformer架构是AI大模型(如GPT、Llama等)的核心基石,彻底颠覆了传统RNN/LSTM的逐字计算模式,通过自注意力机制实现全局并行运算和长文本语义理解。本文用通俗语言拆解Transformer的核心模块:位置编码保留语序、多头注意力捕捉上下文关联、掩码机制确保生成逻辑、残差连接稳定训练,并搭配极简PyTorch代码演示Decoder架构的逐字生成过程。Transformer的并行性、可堆叠性和全局注意力优势,使其成为千亿参数大模型的基础。理解Transformer是掌握大模型

unber的博客 42

TCP/IP 三次握手、四次挥手原理

第一部分TCP/IP三次握手原理1、TCP/IP三次握手示意图SYN:同步序号。ACK:应答回复。RST:复位连接,清除旧有的同步序号。PSH:尽可能的将数据送往接收进程。FIN:发送方完成数据发送。LISTEN:监听是否有连接请求包。SYN_RECV:该状态处于向发送连接请求方回应我已经收到了你的连接请求阶段。SYN_SEND:该状态处于已发出连接请求包,等待对方回应...

weixin_34233856的博客 138

51单片机计算器(源程序+流程图+答辩报告+综合设计)

保姆级讲解!C语言编程,使用51单片机及LCD1602显示屏实现!

m0_57007304的博客 2万+

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

简述TCP/IP协议三次握手和四次挥手

TCP/IP协议 互联网协议(Internet Protocol Suite)是一个网络通信模型,以及一整个网络传输协议家族,为互联网的基础通信架构。它常被通称为TCP/IP协议族(英语:TCP/IP Protocol Suite,或TCP/IP Protocols),简称TCP/IP。 TCP的6种标志符 SYN(synchronous),建立联机 ACK(acknowl...

Keen to coding 的博客 2万+

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

tcp/ip协议三次握手、四次挥手

tcp/ip协议三次握手、四次挥手TCP报文格式两次握手三次握手四次挥手 TCP报文格式 32位序号:随机生成,唯一标识当前报文的序号是多少,seq表示 32位确认序号:对上一条发送的信息进行一个消息的确认,ack表示 ACK:确认标志位,一位,只能表示0/1。 SYN:1:发起一个新的连接 FIN:1:结束一个连接 两次握手 说明:客户端向服务端发送报文,服务端收到了,说明服务端接受客户端的消息没问题。但服务端发给客户端的消息,客户端一定能收到么?服务端还是不知道。 为了安全可靠: 1:客户端知道我

weixin_43303455的博客 6295

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

TCP/IP协议介绍——三次握手四次挥手

在TCP/IP连接中,为了确保双方都能准备好发送和接收数据,会进行一系列的控制信号交换,这其中包括了“三次握手”来建立连接和“四次挥手”来关闭连接。三次握手和四次挥手是TCP协议中建立连接和释放连接的重要过程,它们确保了数据传输的可靠性和连接的正确管理。

u011565038的博客 2706

TCP/IP的三次握手和四次挥手

什么是TCP/IP 首先来说,TCP/IP协议是浏览器与服务器链接因特网的协议。浏览器使用TCP/IP协议进入服务器,服务器使用TCP/IP协议来发送HTML文件到浏览器。 TCP/IP的作用 TCP/IP(Transmission Control Protocol / Internet Protocol)是一个让已连接因特网的计算机进行互相通信的协议。这个协议控制的不仅仅是计算机接入因特网,也有其他电子设备,以及他们之间如何传输数据。 TCP/IP的三次握手 目的: 为了对每次发送的数据量进行跟踪与协.

githubcurry,985cs博士在读 3360

探秘 TCP/IP 的三次握手与四次挥手:细节与故障排查

在四次挥手过程中,客户端从 ESTABLISHED 状态开始,发送 FIN 报文后进入 FIN_WAIT_1 状态,收到服务器的 ACK 报文后进入 FIN_WAIT_2 状态,收到服务器的 FIN 报文后进入 TIME_WAIT 状态,最终进入 CLOSED 状态。服务器从 ESTABLISHED 状态开始,收到客户端的 FIN 报文后进入 CLOSE_WAIT 状态,发送自己的 FIN 报文后进入 LAST_ACK 状态,收到客户端的 ACK 报文后进入 CLOSED 状态。

wire290的博客 2422

TCP/IP协议三次握手、四次挥手详解

由于首部可能含有可选项内容,因此TCP报头的长度是不确定的,报头不包含任何任选字段则长度为20字节,4位首部长度字段所能表示的最大值为1111,转化为10进制为15,15*32/8 = 60,故报头最大长度为60字节。每个连接方通常都在通信的第一个报文段(为建立连接而设置SYN标志为1的那个段)中指明这个选项,它表示本端所能接受的最大报文段的长度。)状态,等待服务器发送连接释放报文,服务器将最后的数据发送完毕后,就向客户端发送连接释放报文,服务器就进入了。主动打开连接的为客户端,被动打开连接的是服务器。

DZQ1223的博客 2334
上一篇: Windows 安装 MongoDB的 zip 版本
下一篇: Java锁升级
牧竹子
博客等级 码龄17年 572粉丝 233原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值