TCP and UDP are bound to the same port for communication

Source: Internet
Author: User

The communication port that can be named and addressable in the network is a resource that can be allocated by the operating system.

According to the description of the OSI Layer-7 protocol, the main difference between the transport layer and the network layer is that the transport layer provides process communication capabilities. In this sense, the final address of network communication is not only the host address, but also an identifier that can describe the process. To this end, the TCP/IP protocol puts forward the concept of protocol port (port), which is used to identify the communication process.

A port is an abstract software structure (including some data structures and I/O buffers ). After an application (process) establishes a binding with a port through a system call, the data transmitted by the transport layer to the port is received by the corresponding process, the data sent by the corresponding process to the transport layer is output through this port. In TCP/IP implementation, port operations are similar to General I/O operations. A process obtains a port, which is equivalent to obtaining a local unique I/O file, it can be accessed using common read/write primitives.

Similar to file descriptors, each port has an integer identifier called port number, which is used to distinguish different ports. Because the TCP and UDP protocols of the TCP/IP transport layer are completely independent software modules, their respective port numbers are also independent of each other. For example, TCP has a port 255, UDP can also have port 255, which does not conflict with each other.

Port number allocation is an important issue. There are two basic allocation modes: the first is global allocation, which is a centralized control mode. A recognized central organization uniformly allocates the results according to user needs and publishes them to the public. The second is local allocation, also known as dynamic connection. When a process needs to access the transport layer service, it applies to the local operating system. The operating system returns a unique local port number, the process then associates itself with the port number through appropriate system calls (bundled ). The above two methods are integrated in TCP/IP Port number allocation. TCP/IP divides the port number into two parts. A small number of reserved ports are allocated to the service process globally. Therefore, each standard server has a globally recognized Port
Port), even on different machines, the port number is the same. The remaining ports are free ports and allocated locally. Both TCP and UDP stipulate that port numbers smaller than 256 can be reserved.

 

 

· Let's talk about how a server monitors a port, such as port 80, and how can it establish thousands of connections?

 

First, a TCP connection needs to be formed by four tuples, namely (src_ip, src_port, dst_ip, dst_port ). When a connection request is sent, the server calls the accept function to generate a new socket. The local port occupied by this socket is still port 80. It is easy to analyze from the four tuples. For the same (src_ip, src_port), the corresponding (dst_ip, dst_port) can be infinitely changed, so that you can create many client requests.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.