Network Programming 1
network communication protocol
The most widely used protocol today is TCP/IP (Transmission Control Protocal/Internet Protoal Transmission Control Protocol/Internet Interconnection Protocol).
The TCP/IP protocol has a relatively simple hierarchy, divided into four layers.
link layer : The link layer is used to define the physical transmission channel, usually a driver protocol for certain network connected devices, e.g. drivers provided for fiber optics, network cables.
network layer : The network layer is the core of the entire TCP/IP protocol, which is used to group the transmitted data and send the grouped data to the target computer or network.
transport layer : This mainly enables network programs to communicate, and when doing so, either the TCP protocol or the UDP protocol can be used.
application layer : Mainly responsible for application protocols, such as HTTP protocol, FTP protocol, etc.
IP address and port number
For the computers in the network to be able to communicate, each computer must be assigned an identification number by which to designate the computer receiving data or the computer sending data.
In the TCP/IP protocol, this identification number is IP address It can uniquely identify a computer.
A computer on a network can go to another computer by IP address and access an application in the target computer by port number.
This class is used to encapsulate an IP address and provides a set of methods related to IP addresses.
UDP is a connectionless communication protocol, which means that no logical connection is established between the sender and receiver of data during data transmission.
Because of the low resource consumption and efficient communication using the UDP protocol, it is usually used for audio, video and general data transmission.
The TCP protocol is a connection-oriented communication protocol, which means that a logical connection is established between the sender and receiver before data is transmitted.
Each time a connection is created it needs to go through the " Three handshakes. ". On the first handshake, the client sends a connection request to the server side and waits for an acknowledgement from the server, on the second handshake, the server side sends a response back to the client informing it that the connection request has been received, and on the third handshake, the client sends an acknowledgement message to the server side again to confirm the connection.
Due to the connection-oriented nature of the TCP protocol, it ensures the security of the transmitted data.