Home  >  Article  >  Operation and Maintenance  >  Overview of the transport layer: the relationship between ports and processes

Overview of the transport layer: the relationship between ports and processes

齐天大圣
齐天大圣Original
2020-12-18 20:00:333184browse

Inter-process communication

The transport layer is also called the transport layer, which is a special layer. On the one hand, it belongs to the highest level of the communication part, and on the other hand, it is the lowest level of user functions. The transport layer is used for communication between processes on different hosts. For routers that forward packets, it only has the functions of the lower three layers and does not use the transport layer and above.

Process, that is, the running program. In Linux, when a program runs, the operating system assigns a process number to the process. You can use the command ps aux to view all processes.

# ps aux 
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  51744  2808 ?        Ss   Jul31  16:06 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
……

Port

The transport layer of TCP/IP uses a 16-bit port number to mark a port, so a host can have 65535 ports . Those who have done web opening must know some commonly used port numbers, such as: 80 of the web server, 3306 of the mysql service and other ports. The processes between the two hosts communicate through their respective port numbers, so the process must also have the function of listening on the port. In Linux, the command to view the monitored port is netstat -tlunp

# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      2449/nginx: worker  
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1010/pure-ftpd (SER 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1819/sshd           
……

The port also has the function of multiplexing and demultiplexing. Multiplexing means that multiple application processes of the host can use the same port number to communicate. , and splitting means that the datagrams obtained from the IP layer can be handed over to different application processes through port numbers.

TCP and UDP

The transport layer has only two protocols: Transmission Control Protocol TCP and User Datagram Protocol UDP. These two protocols have their own characteristics and some application scenarios.

TCP is a connection-oriented protocol. A connection must be established before data is transmitted. If data transmission is not required, the connection needs to be disconnected. TCP is a relatively complex protocol with many factors to consider. It can provide end-to-end reliable transmission, but does not support one-to-many and many-to-many communications. Commonly used TCP protocols include HTTP protocol, ftp protocol, telnet protocol, etc.

UDP is for packets. It is relatively simple and uses best efforts rather than reliable transmission. It can perform one-to-one, one-to-many and many-to-many communication. Common protocols that use UDP protocol include DHCP, DNS, and RIP protocols.

There is an example to illustrate their characteristics: TCP is like making a phone call. A connection must be established before the call. UDP is like sending a text message. You don't need to know the status of the other party's host before sending the text message. You don't know whether the text message has been sent or not.

The above is the detailed content of Overview of the transport layer: the relationship between ports and processes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn