Protocol family and data transmission method

table of Contents

1. Protocol and protocol family (Protocol)

2. Data transmission method

2.1、SOCK_STREAM

2.2、SOCK_DGRAM


1. Protocol and protocol family (Protocol)

Protocol (Protocol) is the agreement of network communication, and both parties of communication must abide by it in order to send and receive data normally. There are many protocols, such as TCP, UDP, IP, etc. Both parties in communication must use the same protocol to communicate. A protocol is a specification, formulated by a computer organization, which stipulates many details, such as how to establish a connection and how to identify each other.

The so-called protocol family (Protocol Family) is a collective term for a group of protocols (multiple protocols). The most common is the TCP/IP protocol suite, which includes hundreds of mutually related protocols such as TCP, IP, UDP, Telnet, FTP, and SMTP. Because TCP and IP are two commonly used underlying protocols. Therefore, they are collectively referred to as the TCP/IP protocol suite.

2. Data transmission method

There are many ways to transfer data between computers, there are two common ones: SOCK_STREAM and SOCK_DGRAM

2.1、SOCK_STREAM

SOCK_STREAM represents a connection-oriented data transmission method. The data can arrive at another computer without error, and if it is damaged or lost, it can be resent, but the efficiency is relatively slow. The common http protocol uses SOCK_STREAM to transmit data, because it is necessary to ensure the correctness of the data.

Why can stream format sockets achieve high-quality data transmission? This is because it uses the TCP protocol (The Transmission Control Protocol). The TCP protocol will control your data to arrive in order without errors.

TCP/IP: TCP is used to ensure the correctness of data, and IP (Internet Protocol) is used to control how data arrives at its destination from the source, which is often referred to as "route".

So, how to understand "data sending and receiving are out of sync"?

There is a buffer (that is, a character array) inside the stream format socket, and the data transmitted through the socket will be stored in this buffer. The receiving end does not necessarily read the data immediately after receiving the data. As long as the data does not exceed the capacity of the buffer, the receiving end may read it once after the buffer is filled, or it may be read several times.

In other words, no matter how many times the data is transmitted, the receiving end only needs to read it according to its own requirements, and does not have to read it immediately when the data arrives. The transmitting end has its own rhythm, and the receiving end has its own rhythm. They are inconsistent.

2.2、SOCK_DGRAM

SOCK_DGRAM represents a connectionless data transmission method. The computer just transmits the data and does not perform data verification. If the data is damaged during transmission or does not reach another computer, there is no way to remedy it. In other words, if the data is wrong, it is wrong and cannot be retransmitted. Because SOCK_DGRAM does less verification work, it is more efficient than SOCK_STREAM

The datagram socket also uses the IP protocol for routing, but it does not use the TCP protocol, but uses the UDP protocol (User Datagram Protocol, user datagram protocol)

SOCK_DGRAM is not as bad as imagined. Data will not be lost frequently. Data errors are only a small probability event.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_40179091/article/details/113028061