当前位置:网站首页>How to connect the network: Chapter 1 CSDN creation punch in
How to connect the network: Chapter 1 CSDN creation punch in
2022-07-03 05:01:00 【wzyAcyy】
The user enters a... Into the browser URL The response returns , The life cycle of a network request .
The whole book is divided into six parts :
- Application layer client generation HTTP, Protocol stack delegated to the operating system
- Protocol stack (TCP/IP modular ) Call the network card driver to generate an electrical signal
- How does the network card reach the router used to access the Internet through the router
- Internet internal relay transmission
- arrive web The server passes the firewall first
- web How does the server collect data
The first chapter introduces , The client application parses URL The process of sending to the delegation protocol stack :
- The application layer client is based on url Protocol format extraction , Domain name or ip,port,URL, Request parameters and other information
- according to HTTP The protocol generates a request message
- Before sending a message , You need to know about each other's IP, entrust DNS The client parser uses the domain name to pass DNS Server acquisition IP
- Use Socket Library delegation protocol stack (TCP/IP) Send a request
Generate HTTP Request information
Browser enter web address (URL)
URL Uniform Resource Locator Uniform resource locator
URL Format – Protocol type :// Form of agreement
Use US-ASCII
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
use HTTP Agreement to access Web Server time
http://user:[email protected]:80/dir/file1.htm
http://[ user name ]:[ password ]@web Server domain name :[ Port number ] File pathname
ftp Upload and download files
ftp://user:[email protected]:21/dir/file1.htm
ftp://[ user name ]:[ password ]@ftp Server domain name :[ Port number ] File pathname
file://localhost/c:/path/file.zip
file://[ Computer name ] File pathname
HTTP summary
Hypertext transfer protocol (HTTP) It's a kind of distributed , cooperative , Multimedia information system services , Application layer oriented protocols
HTTP Form of agreement
The request message
< Method >< Space ><URI>< Space ><HTTP edition >
< Field name >:< field value >
< Field name >:< field value >
< Field name >:< field value >
...
< Blank line >
< Message body >
The response message
<HTTP edition >< Space >< Status code >< Space >< Response phrase >
< Field name >:< field value >
< Field name >:< field value >
< Field name >:< field value >
...
< Blank line >
< Message body >
Request header classification : Universal head ( Applies to request headers Response head ) Request header Response head Entity head
Response code | Response phrase
1xx | Inform the request processing progress and situation
2xx | success
3xx | Indicates that further operation is required
4xx | Client error
5xx | Server error
Only one request can be written URI, html and Pictures require separate requests
WWW working principle , Text data and embedded image data in web pages are stored independently | Separate the requested
towards DNS Server query Web Server's IP Address
The previous step generated HTTP news , Before sending, you need to know the server of the other party IP.
DNS: Domain Name System Source server
IP Address
IP It consists of network number and host number , The dividing line between the network number and the host number is divided by the subnet mask .
ip View instructions
windows ipconfig
linux ifconfig
Illustrate with examples :
ip: 10.11.12.13
Subnet mask : 255.255.255.0
network number :10.11.12
Host number :13
32 bit, 8 bit A group of
a. IP The representation of the address body
10.11.12.13
IP Address
b. Subnet mask expression
10.11.12.13/255.255.255.0
IP Address body / Subnet mask
c. The subnet mask is represented by the number of network number bits
10.11.12.13/24
IP Address body / Subnet mask
d. Indicates the address of the subnet
10.11.12.0/24
All bits of the host number are 0 Represents the whole subnet
d. Indicates the address of the subnet
10.11.12.255/24
All bits of the host number are 1 The representative broadcasts to the subnet
ip Address 10.11.12.255
Subnet mask 255.255.255.0
The subnet mask represents the boundary between the network number and the host number , Subnet mask 1 Part of the network number , 0 Some host numbers of
Number of network number bits : 24 == 255.255.255.0
Domain name and IP Address combination
Human domain name , Easy to remember
Routers use IP, Address length 32bit 4 byte , Network transmission efficiency is high , Good performance
note: If the server uses a virtual host , May not work IP visit
How to query IP
1. Ask about the latest DNS The server , The domain name will correspond to IP
2. DNS Server return IP
There will be one on the computer DNS client be called DNS Parser
adopt DNS Inquire about IP It is called domain name resolution
The parser is actually a program , Included in the operating system Socket In the library
Socket library Developed by the University of California, Berkeley BSD(UNIX operating system ) Medium C Language library , Other language references Socket Developed the corresponding network library
Socket library It is a collection of program components used to call network functions , Standard library of network development
BSD (Berkeley Software Distribution, Berkeley Software Distribution )
https://baike.baidu.com/item/BSD/3794498?fr=aladdin
adopt DNS Parser towards DNS The server Send query
< Memory address > = gethostbyname(" domain name ");
Parser workflow
When a web application calls the parser , The control flow of the program will be transferred to the inside of the parser .
1. Application calls DNS Parser
2. DNS Parser Generate DNS Server query message , Call protocol stack (TCP/IP drive )
3. Protocol stack sends messages
4. Send a message to DNS The server .
HTTP Message text , DNS Messages are in binary
Control process transfer : Applications call other programs , The originally running program enters a suspended state , The called program starts running .
All over the world DNS The server Big relay
DNS The workflow of the server
1. Receive query messages from clients
2. Return the response according to the message content
Query message format
a) domain name
The server , Mail server ([email protected] @ The following paragraph ) name
b) Class
Type always represents the Internet IN
c) Record type
A: The server
MX(mail eXchange): Mail server
Response message format
The record type is A return The server corresponds to IP
The record type is MX return Priority and domain name corresponding to the mail server
priority : When one email address corresponds to multiple email servers , The smaller the number, the higher the priority
domain name | Class | Record type | The response data |
---|---|---|---|
www.baidu.com | IN | A | xxx.xxx.xxx.xxx |
glasscom.com | IN | MX | 10 mail.glasscom.com |
mail.glasscom.com | IN | A | xxx.xxx.xxx.xxx |
Domain name hierarchy
Save according to the hierarchical structure of the domain name
www.baidu.com Period separation , The more right, the higher the level
Can direct Baidu " Domain name hierarchy "
Look for the corresponding DNS Server and get IP Address
1. Register from bottom up
2. Top down query
register
DNS The server A( management baidu.com)
DNS The server B( management com)
A register baidu.com as well as A Of ip To B
B register com as well as B Of ip To root server (.)
The name of the root domain server IP Store in all DNS Server
The name of the root domain server IP The world is just 13 individual , Use multiple servers for one IP
Inquire about
The client accesses the nearest DNS The server K, K Of ip On the client side TCP/IP There are
for example www.baidu.com
K Access root domain , return com Where the domain is located ip
K visit com Domain , return baidu Where the domain is located ip
K visit baidu Domain , return www Where the domain is located ip
K visit www Domain , return www.lab.glasscom.com Where ip
Last K return ip To the client
DNS Server cache acceleration
After querying the domain name DNS The server will cache
If the domain name does not exist, it will be cached
DNS The cache information in the server will set a validity period . And will inform the client , The response result comes from the cache or the server that manages the domain name
cache : Store the used data in a high-speed storage device close to the data used , In order to improve the speed of subsequent access .
CPU And memory Between disk and memory Network cache
Delegate protocol stack to send message
Data sending and receiving operation
Call... In order Socket Program components in the library , towards OS The internal protocol stack sends the delegation .
1. Create socket ( Create socket phase )
2. Connect the pipe to the server socket ( Connection phase )
3. Manipulation data ( Communication stage )
4. Disconnect and delete socket ( Disconnection phase ) It can be initiated by either side of the client server , Usually the server
< Memory address > = gethostbyname("www.baidu.com");
< The descriptor > = socket(<ipv4>, < Flow mode >);
connect(< The descriptor >, < Server's IP Address and port number >, ...);
write(< The descriptor >, < send data >, < Send data length >);
< Length of received data > = read(< The descriptor >, < Receive buffer >, ...);
close(< The descriptor >);
this 5 Each operation is an application delegate OS Protocol stack to execute .
These delegate operations are done by calling Socket The program components in the library execute ,Socket The library acts as a bridge between applications and protocol stacks
socket(<ipv4>, < Flow mode >); A detailed explanation of parameters is attached (https://blog.csdn.net/lee244868149/article/details/43732025)
TCP It's a streaming protocol
UDP Is a datagram mode protocol
In this paper Socket/socket/ Socket
Socket, Representation Library
socket, Indicates the name of the program component
Socket , Represents the interface at both ends of the pipe , Abstract of the endpoint for two-way communication between application processes on different hosts in the network . The socket is connected to the application process , Lower network protocol stack , It's an interface for applications to communicate through network protocols , It is the interface between application program and network protocol stack .
Create socket
< The descriptor > = socket(<ipv4>, < Flow mode |bio|nio>)
Applications 、 The operating system identifies sockets through socket descriptors
Through descriptors , The protocol stack can find the corresponding socket
Connection phase
connect(< The descriptor >, < Server's IP Address >, < Server port number >, ...);
The descriptor : The protocol stack judges which socket to use to connect with the socket of the server according to the descriptor , And perform the connection
The server IP: Identify the server
Server port : Identify the socket on the server
When creating a socket , The protocol stack will assign a port number ( You can also specify ). Notify the server of this port number when connecting
call connect when , Perform the connect operation . After successful connection , The agreement will put the other party IP PORT And other information is saved in the socket
The descriptor 、 The relationship between port number and socket
The descriptor : The mechanism that applications use to identify sockets
IP+PORT: The mechanism between client and server to identify each other's socket
IP Address is assigned to the network hardware installed in the device . If a device has multiple network hardware, there are multiple IP
Default port number
http 80
tomcat 8080
E-mail 25
Communication stage : The message
write(< The descriptor >, < send data >, < Send data length >);
< Length of received data > = read(< The descriptor >, < Receive buffer >, ...);
adopt socket call read write Delegate the protocol stack to send and receive information
The receive buffer is located inside the application , Storing the message in the receive buffer is equivalent to forwarding it to the application
Disconnection phase : End of sending and receiving data
The application receives data , The process of sending and receiving data is over . Next call Socket Of close Enter the disconnection phase .
Finally, the socket and pipe are disconnected , The socket itself will be deleted .
Depending on the type of application , Which side is the client and server first close. Some application clients execute first , Some servers execute first .
Disconnect process
HTTP Provisions of the agreement : Disconnect the server first
web After the server sends the response message , Actively perform disconnection , First call close disconnect
web The client receives a disconnect signal , Enter the disconnection phase
Next , browser ( Applications ) call read receive data ,read Tell the browser ( Applications ) Sending and receiving data operation has ended , connection dropped
browser ( Applications ) After learning that , call close Enter the disconnection phase
HTTP 1.1 Start connection multiplexing
The protocol stack is actually responsible for sending and receiving messages 、 network card 、 drive
边栏推荐
- The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
- 论文阅读_清华ERNIE
- I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
- [set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
- Actual combat 8051 drives 8-bit nixie tube
- Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
- RT thread flow notes I startup, schedule, thread
- M1 Pro install redis
- cookie session jwt
- What is UUID
猜你喜欢
[research materials] annual report of China's pension market in 2021 - Download attached
论文阅读_ICD编码_MSMN
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
Sdl2 + OpenGL glsl practice (Continued)
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
2022-02-12 daily clock in: problem fine brush
Thesis reading_ Chinese NLP_ ELECTRA
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
RT thread flow notes I startup, schedule, thread
随机推荐
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
[SQL injection] joint query (the simplest injection method)
2022-02-11 daily clock in: problem fine brush
Market status and development prospect prediction of global SoC Test Platform Industry in 2022
Thesis reading_ Chinese medical model_ eHealth
移动端——uniapp开发记录(公共请求request封装)
1086 tree traversals again (25 points)
联发科技2023届提前批IC笔试(题目)
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
sql语句模糊查询遇到的问题
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
Notes | numpy-09 Broadcast
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Review the old and know the new: Notes on Data Science
Market status and development prospects of the global IOT active infrared sensor industry in 2022
Learn to use the idea breakpoint debugging tool
Do you know UVs in modeling?
1115 counting nodes in a BST (30 points)
Messy change of mouse style in win system
Apache MPM model and ab stress test