输入URL后会发生什么
- 调用浏览器渲染引擎(譬如V8),解析网络请求,解析执行JS,UI后端渲染
- 从URL中解析域名,根据域名查询DNS
- 在浏览器DNS缓存中查询
- 在操作系统DNS缓存中搜索
- 系统Hosts文件中查询
- 向本地DNS服务器发起Query请求(UDP)
- 与Server进行TCP握手(+TLS握手)
- 构造HTTP请求,填充上下文到HTTP头
- 发送HTTP请求,收到HTML页面作为响应
- 浏览器引擎解析响应,并渲染至界面,根据HTML文档中超链接再构造HTTP请求
- 发起获取页面资源的HTTP请求
- 三次握手
- C: SYN->
- S: <-SYN,ACK
- C: ACK->
- 四次挥手
- FIN->
- <-ACK
- <-FIN,ACK
- ACK->
- 状态机图
+---------+ ---------\ active OPEN
| CLOSED | \ -----------
+---------+<---------\ \ create TCB
| ^ \ \ snd SYN
passive OPEN | | CLOSE \ \
------------ | | ---------- \ \
create TCB | | delete TCB \ \
V | \ \
+---------+ CLOSE | \
| LISTEN | ---------- | |
+---------+ delete TCB | |
rcv SYN | | SEND | |
----------- | | ------- | V
+---------+ snd SYN,ACK / \ snd SYN +---------+
| |<----------------- ------------------>| |
| SYN | rcv SYN | SYN |
| RCVD |<-----------------------------------------------| SENT |
| | snd ACK | |
| |------------------ -------------------| |
+---------+ rcv ACK of SYN \ / rcv SYN,ACK +---------+
| -------------- | | -----------
| x | | snd ACK
| V V
| CLOSE +---------+
| ------- | ESTAB |
| snd FIN +---------+
| CLOSE | | rcv FIN
V ------- | | -------
+---------+ snd FIN / \ snd ACK +---------+
| FIN |<----------------- ------------------>| CLOSE |
| WAIT-1 |------------------ | WAIT |
+---------+ rcv FIN \ +---------+
| rcv ACK of FIN ------- | CLOSE |
| -------------- snd ACK | ------- |
V x V snd FIN V
+---------+ +---------+ +---------+
|FINWAIT-2| | CLOSING | | LAST-ACK|
+---------+ +---------+ +---------+
| rcv ACK of FIN | rcv ACK of FIN |
| rcv FIN -------------- | Timeout=2MSL -------------- |
| ------- x V ------------ x V
\ snd ACK +---------+delete TCB +---------+
------------------------>|TIME WAIT|------------------>| CLOSED |
+---------+ +---------+