OSI network seven – layer reference model

This is the non-implementation level of the 7-layer network reference modelCopy the code

TCP/IP protocol implementation

TCP/IP implements a seven-layer network model that combines the presentation layer and session layer into the application layer. Wechat, QQ, or Tomcat processes belong to the application layer. Common protocols of this layer are HTTP, HTTPS, SSH, and FTP For example, the transmission control layer (TCP, UDP), network layer (IP, routing protocol), link layer (ARP protocol) is implemented by the kernel user mode through system call switch to the kernel stateCopy the code

Demonstrate network interaction

Log in to the Linux operating system through SSH and run the exec command to access Baidu and retrieve the baidu home page without any browser or tools. This process involves the user layer, kernel, TCP communication and HTTP protocolCopy the code

exec 8<> /dev/tcp/www.baidu.com/80

/ dev/tcp/www.baidu.com/80 a path prefix is/dev/TCP everything Linux operating system file Network connection can be a file The printer can be a file To represent the kernel in the form of file directory will eventually converts it into the socketCopy the code

So once we do that we have an 8 in the current field and the input and output of that 8 point to this socket in Baidu and now let's say we have a three-way handshake socket so what do we have to send to baidu to fetch the home page of the baidu server in order to get it back which protocol is involved and we need to send an HTTP protocol to BaiduCopy the code

GET/HTTP / 1.0 \ n

/ represents the requested resource and you send this string to Baidu and Baidu knows that you're going to request the home page and the protocol is how do you represent the data that you send and the HTTP protocol is how does the data represent the HTTP protocolCopy the code

Echo -e "GET/HTTP/1.0\n"

Echo is used to print and identify the newline character through -e. N HTTP is used to cut the newline character to get a string of lines. Each string is cut with a spaceCopy the code

Echo -e "GET/HTTP/1.0\n" 1> &8

The output of standard output 8 points to Sokcet. If baidu receives it, it will be returned. Then it needs to read the returned content. Socket network communication is bidirectionalCopy the code

cat 0<& 8

Read the contents returned from Socket 8Copy the code

If it hasn't been read for a long time then it will disconnect and try againCopy the code

When you read the HTTP/1.0 that baidu returns, 200 OK is the response header followed by the key-value pair of the response header followed by 2 newlines followed by the body of the response which is the home page of Baidu and when you fetch something it will disconnectCopy the code

cd /proc/$$/fd

The current interpreter process ID is 1307 fd is the file descriptor. Any program that has IO will open a file. Socket is also a fileCopy the code

In 1 is the standard input system. Out 2 is system. Error. These three sockets are available to any program and can be given a number or an increasing number to represent the socket The fd file descriptor can be understood as a variable. In Java, opening a file yields a file variableCopy the code

lsof -p $$

012 is the input/output to the terminal

9 is a TCP

The local random port number points to an address of Baidu. The port number 80 is HTTP protocol 9, which represents a socket for Baidu. It's actually done by the kernelCopy the code

conclusion

The connection doesn't have to be managed by a human being and then the communication between the client and the server is what? The HTTP protocol is connected to the Web server so the HTTP protocol is connected to the FTP server and the FTP protocol application is connected to the protocol encapsulation process in the application and the protocol encapsulation process is not done by the kernel but by some software such as browser, Postman, HTTP The client user doesn't have to worry about protocol encapsulation when they use the browser just tell them what to access, okayCopy the code

This article is formatted using MDNICE