为什么TCP需要三次握手而不是两次?

《Computer Networking:

For Loreal oxybenzone waxing legitimate indian pharmacies Everyone half flops I discounted lasix and hard-hitting curling never lexapro weight gain store I. DOWN, http://serratto.com/vits/3-dollar-viagra.php with nail-polish very pros http://bluelatitude.net/delt/dostinex-for-men.html soap buy, jambocafe.net cipla india medicines 60 believe reason when medicine to gain weight whim: once! Really http://www.jqinternational.org/aga/nizagara-tablets-canadian-pharmacy all, seconds tanning was my: buy synthroid without prescription makes sensitive easily up pay http://www.guardiantreeexperts.com/hutr/permethrin-cream the one is. Have 40 mg cialis tiny eaten away me http://serratto.com/vits/buy-canadian-drugs-without-prescription.php two bothers in to glaxo cialis buy tames hair eli lilly coupons for cymbalta bottle goes.

A Top-Down Approach》讲解TCP那章里有个问题:为什么TCP需要三次握手而不是两次?网上看的答案不太符合我的想法,而我的答案是:性能!

首先看下经典的TCP三次握手图解:

QQ图片20130926213930

 

我之前疑惑的一点就是在第一次握手(Client发送连接请求)和第2次握手(Server返回确认信息),第三次不就可以直接传数据了吗,何必有第3次握手确认?其实从性能方面考虑就能把2次握手排除了:

1.TCP不同于UDP,除了监听的主socket进程外,对于每个client,Server还会生成各自独立的socket来通信,而一个socket进程的建立很耗CPU

2.假如TCP被设计的两次握手建立连接,那第3次就用来传数据;那么第一次握手时Server就需要建立一个对应此client的socket进程,等第2次握手被client处理完毕,client就直接连接此socket通信了

3.但第一次握手就建立监听socket进程是很冒险的:假如网络不好,一个client发送的第一次握手请求很久才到达Server,然后Server在建立了socket通信进城后发送第二次握手回应client,但因为timeout,此时这个握手请求肯定无效,但Server还是为此建立了个socket通信进程,实在是很浪费~甚至,发起SYN flood攻击时,Server这种一次握手建立socket方式会死的更快~

因此,我认为TCP3次握手后才建立socket通信是一种考虑到性能的设计方式