OSI is the abbreviation of Open System Interconnection, which means open system interconnection.
The OSI seven-layer protocol model is mainly: application layer (Application), presentation layer (Presentation), session layer (Session), transport layer (Transport), network layer (Network), data link layer (Data Link), physical layer ( Physical).
1、 Physical layer
Mainly define the physical equipment standards, such as the interface type of the network cable, the interface type of the optical fiber, and the transmission rate of various transmission media. Its main function is to transmit bit stream (that is, from 1, 0 to current strength for transmission,After arriving at the destination, it is converted into 1, 0, which is what we often call digital-to-analog conversion and analog-to-digital conversion). The data in this layer is called bits.
2、 data link layer
It defines how to format data for transmission and how to control access to physical media. This layer usually also provides error detection and correction to ensure reliable data transmission.
3、 Network layer
Provide connection and path selection between two host systems in networks located in different geographical locations. The development of the Internet has greatly increased the number of users accessing information from various sites in the world, and the network layer is the layer that manages this connection.
4、 Transport layer
Some protocols and port numbers for data transmission (WWW port 80, etc.) are defined, such as:
TCP (transmission control protocol-transmission control protocol, low transmission efficiency, high reliability, used to transmit data with high reliability requirements and large amounts of data)
UDP (user datagram protocol-user datagram protocol, contrary to TCP characteristics, used to transmit data with low reliability requirements and small data volume, such as QQ chat data is transmitted in this way). It is mainly to segment and transmit the data received from the lower layer, and then reorganize it after reaching the destination address. This layer of data is often called a segment.
5、 Session layer
The data transmission path is established through the transport layer (port number: transmission port and receiving port). Mainly initiate sessions or accept session requests between your systems (devices need to know each other, which can be IP, MAC or hostname)
6、 Presentation layer
It can ensure that the information sent by the application layer of one system can be read by the application layer of another system. For example, a PC program communicates with another computer, one of which uses Extended Two Decimal Interchange Code (EBCDIC), and the other uses American Standard Code for Information Interchange (ASCII) to represent the same characters. If necessary, the presentation layer uses a common format to convert between multiple data formats.
7、 Application layer
It is the OSI layer closest to the user. This layer provides network services for user applications such as email, file transfer, and terminal emulation.
\1. C/S architecture and its background
The C/S architecture is an earlier software architecture mainly used in local area networks. Prior to this, I experienced a centralized computing model. With the progress and development of computer networks, especially the application of visualization tools, there have been two-tier C/S and three-tier C/S architectures, but we have always been very popular and classic. The two-tier C/S architecture to be studied.
C/S architecture software (that is, client/server model) is divided into two layers: client and server: the first layer combines presentation and business logic on the client system, and the second layer combines the database server through the network. Simply put, the first layer is the user presentation layer, and the second layer is the database layer. The client and the server are directly connected, and these two components both play important roles.
2. C/Advantages of S architecture
a.The client and the server are directly connected. The point-to-point connection is more secure, and local text can be directly manipulated, which is more convenient.
b.The client can handle some logical transactions. Data processing and data storage can be performed, and certain help can be provided.
c.The client directly operates the interface.
3. C/Disadvantages of S architecture
a> C/The S architecture is suitable for local area networks, and requires relatively high network speed.
b>The client interface lacks versatility, and when the business changes, the interface needs to be changed and rewritten.
c>As the number of users increases, there will be communication congestion and slow server response.
d>System maintenance is also troublesome.
4. C/Application of S architecture
C/There are countless S architecture software, from office office, WPS, WINRAR to anti-virus software such as Kingsoft, Ruijin to our entertainment software, such as players, QQ, WeChat, etc. C is everywhere./S architecture.
[

Copy code
]( javascript:void(0);)
\1. B/S structure and its background
With the popularity of the Internet and WWW, previous hosts/terminals and C/S cannot meet the current global network openness, interconnection, information everywhere and information sharing new requirements, so the B/S model appeared, namely Browser/server structure. It is an improvement of the C/S architecture, which can be said to belong to the three-tier C/S architecture. It mainly uses the ever-mature WWW browser technology, and uses a general-purpose browser to realize the powerful functions that originally required complex special software to achieve, and saves the development cost. It is a new software system construction technology.

img
The first layer is that the browser (that is, the client) has only simple input and output functions and handles a very small part of the transaction logic. Since customers do not need to install a client, they can browse the Internet as long as they have a browser, so it is aimed at a wide range of users, so the interface design is relatively simple and universal.
The second layer is the WEB server, which plays the role of information transmission. When a user wants to access a database, he will first send a request to the WEB server. After a unified request, the WEB server will send a request to the database server to access the database. This request is implemented in SQL statements.
The third layer is the database server, which stores a large amount of data. When the database server receives the request from the WEB server, it processes the SQL statement and sends the returned result to the WEB server. Next, the WEB server converts the received data result into HTML text and sends it to the browser.
[

Copy code
]( javascript:void(0);)
2. B/Advantages of S architecture
a>The browser and the database server are connected in a many-to-many manner. Therefore, it is suitable for realizing a huge Internet in a wide area network, or even a global network, which has a strong information sharing.
b>The browser only handles some simple logical transactions, and the burden is small.
c>The data is stored centrally in the database server, so there is no data inconsistency.
d>As the server load increases, you can smoothly increase the number of servers and establish a cluster server system, and then load balance among the servers.
e> B/S is built on a wide area network, so the required network speed is not high.
f>No need to install a client, as long as you can connect to the Internet, you can browse the page anytime, anywhere.
g>It can effectively protect the data platform and manage access rights, and ensure the data security of the server database.
3. B/Disadvantages of S architecture
a>The server bears important responsibilities and the data load is heavy. Once server "crash" and other problems occur, the consequences will be disastrous.
b>The page needs to be constantly refreshed dynamically. When the number of users increases, the network speed will slow down.
4. B/Application of S architecture
For example, WEBQQ, from the WEB in the name of WEBQQ, it is not difficult to see that it belongs to B/S architecture is a browser server structure. In fact, the same is true, because WEBQQ does not need to install a client at all, only a browser can be used for chat interaction.
[

Copy code
]( javascript:void(0);)
Initial state: both client A and server B are in the CLOSED state, and then server B creates a socket, calls the listening interface to make the server in the LISTEN state, and waits for the client to connect. (Substitution A and B for the following content)
1、 A first initiates a connection to B. At this time, the value of the SYN flag in the TCP header is 1, and then an initial sequence number seq=x (usually random) is selected. After the message is sent, A enters the SYN_SENT state, with SYN=1 The message segment cannot carry data, but it consumes a sequence number.
2、 After receiving A's connection request, B agrees to establish a connection and sends confirmation data to A. At this time, the SYN and ACK flags in the TCP header are both 1, and the confirmation sequence number is ack=x+1, and then selects its own The initial sequence number seq=y (usually random). After the confirmation message is sent, B enters the SYN_RCVD state. Like the connection message, this message cannot carry data and consumes a sequence number.
3、 After A receives the confirmation message from B, it needs to reply to B with the confirmation data. At this time, the ACK flag in the TCP header is 1, and the confirmation sequence number is ack=y+1, and its own sequence number is added to the sequence number of the connection request. , That is, seq=x+1, at this time A enters the ESTABLISHED state, when B receives the confirmation reply from A, B also enters the ESTABLISHED state, so far TCP successfully establishes a connection, and A and B can send each other through this connection Data.
Initial state: A TCP connection has been established between client A and server B, and the data transmission is complete, and the connection is going to be disconnected. At this time, client A and server B are equivalent, and both parties can send a disconnect request. Take the example of client A actively initiating a disconnect request. (Substitution A and B for the following content)
1、 A first sends a disconnect message to B. At this time, the value of the FIN identification bit in the TCP header is 1, the sequence number is seq=m, and m is the sequence number of the last byte of the normal data sent before A plus 1, after the message is sent A enters the FNI_WAIT_1 state, the segment with FIN=1 cannot carry data, but it consumes a sequence number.
2、 B receives A’s disconnect request and needs to send an acknowledgment message. At this time, the ACK flag in the TCP header is 1, the acknowledgment number is ack=m+1, and its own sequence number is seq=n, n is before B The sequence number of the last byte of data sent normally is increased by 1, and then B enters the CLOSE_WAIT state. At this time, the connection between A and B is closed. A can no longer send data to B, but B can still send data to A (the question is here) ), at the same time, the B-side notifies the upper application layer, and passively closes the connection after the processing is completed. Then after A receives B's confirmation message, it enters the FIN_WAIT_2 state.
3、 After the application layer at the B side finishes processing the data, it notifies the connection to be closed, and B sends a message to close the connection. At this time, the FIN and ACK flags in the TCP header are both 1, and the confirmation number ack=m+1, its own serial number For seq=k, (B sends a piece of data after sending the confirmation message, here is a doubt), B enters the LACK_ACK state after the message is sent.
4、 After A receives B’s disconnect message, it needs to send an acknowledgment message. This is when the ACK flag value in the TCP header is 1, the acknowledgment number ack=k+1, and the sequence number m+1 (because A B consumed a message number when sending a disconnected message), and then A enters the TIME_WAIT state. If the retransmission request from B is not received after the waiting time has elapsed 2MSL, it indicates that B has received its own confirmation and A enters the CLOSED state , B enters the CLOSED state directly after receiving A's confirmation message. So far TCP successfully disconnected.
ARP (Address Resolution Protocol) is the address resolution protocol, which is used to implement the mapping from IP address to MAC address, that is, to query the MAC address corresponding to the target IP.
For details, see https://www.cnblogs.com/csguo/p/7527303.html
[

Copy code
]( javascript:void(0);)
TCP:
The general steps of the server side of TCP programming are:
1. Create a socket, use the function socket();
2. Set the socket attribute, use the function setsockopt();*Optional
3. Bind IP address, port and other information to the socket, use the function bind();4. Turn on monitoring, use the function listen();
5. To receive the connection from the client, use the function accept();
6. To send and receive data, use the function send()And recv(), Or read()And write();7. Close the network connection;
8. Turn off monitoring;
[

Copy code
]( javascript:void(0);)
[

Copy code
]( javascript:void(0);)
UDP:
The corresponding UDP programming steps are much simpler, as follows:
The general steps of the server side of UDP programming are:
1. Create a socket, use the function socket();
2. Set the socket attribute, use the function setsockopt();*Optional
3. Bind IP address, port and other information to the socket, use the function bind();4. To receive data cyclically, use the function recvfrom();5. Close the network connection;
[

Copy code
]( javascript:void(0);)
Basic difference between TCP and UDP
The difference in specific programming
Recommended Posts