About Port Sharing

Source: Internet
Author: User

In the past, the whole socket programming (VB6.0) sometimes forgot to close the socket when it was started again, it was reported that the port had been used. The method was to restart the system. Later, I saw that a port uniquely identifies an application.ProgramSharing port 80, so the world is not harmonious.

To solve this major contradiction, as a 2B programmer, I tried the parallel universe theory and Xuan theory until God's creation said.

Next, let's take a look at my yy. the great gods smiled and hoped to give me some advice.

 

Memories of links

When I was a child, I still remember that there was a switchboard room in the factory. The Master name was Wang, and there was a telephone switch in it. What was the specific name was not clear, that is, a person with a lot of plug-ins in front of a telephone line, these telephone lines are connected to multiple offices in the factory. When Mr. Wang finds Xiao Li, he needs to shake the phone and call the master machine to ask Master Wang to answer the phone. Master Wang often gets wrong lines during the day when playing mahjong at night, it seems that it is very troublesome to transfer external lines. Fortunately, the phone number in the factory is mainly used for chatting and chatting in various departments (for distant relatives, it is generally a letter or a telegram) because everyone is bored at work, they will call the phone, at that time, the line was often busy. Xiao Zhang and Xiao Li were talking about Xing Xiang. Now Wu factory Zhang is looking for Xiao Li, but Master Wang said that Xiao Li is following Xiao Zhang. At this time, Wu factory Zhang sent a message and pulled it out for me, as a result, Jack suddenly fell offline, and Jack suddenly found out how he changed his voice ........., of course, you may think (brother did think about it) Why not pull the root lines in every department. In this way, Master Wang will not be transferred, but after high school (not Junior High School) brother found that the telephone network in China would not be able to pull many lines, and in the factory, if there are 10 departments, each department would need to call ten lines. Brother's understanding of the connection remains at this level, and he has always misunderstood the TCP link, however, after reading this article, you will find that the previous phone number is a stream connection in the true sense (we will not mention the problem of wave-particle binary. ^_^)

TCP link should be an illusion

The key to a digital line is to encode the information and then split it into data packets to send it in one copy, so there will be a so-called delay (encoding, decoding, forwarding, and other time ), in the past, as long as the phone was connected, it was sent at the speed of light.

Both TCP and UDP are sent from the IP datagram layer to the physical layer. For data sent from the IP layer, TCP and UDP are no different. The three handshakes of TCP are even more powerful, of course, there is a protocol identification field in the IP layer datagram to decide whether to send the datagram to the TCP driver or the UDP driver after receiving the IP datagram. From the process description above, we can see that the so-called TCP link is an illusion. In essence, it should be a structure maintained by the TCP Driver (the source IP + port, target IP + port, the initial serial number, as well as the serial number of the last packet to be sent and received), and the server application binding port is essentially for the TCP driver to act as a route sign when receiving the TCP packet.

Can a server port establish TCP connections with many browsers at the same time?

Theoretically, an infinite number of connections can be established on a server port. You can use the [local-IP: Port and remote-IP: Port] combination to differentiate each connection (note the client-connection initiator, A random unused port is used each time, but each link requires a certain amount of memory space (including buffer windows ), and the TCP driver requires multiple threads to maintain these links (CPU resources). Therefore, many TCP Connections cannot be maintained at the same time.

How can I send and receive data packets from multiple websites on the same port?

First, it should not be a problem. The TCP driver sends the data packet back to the corresponding TCP link, and the client process will be able to correctly receive the message (the tcp client does not have a Port Sharing Statement ).
It is a matter of reception, and there is no special identifier on the TCP Header (similar to the cookie mechanism, of course, the existing TCP protocol should not be modified under normal circumstances ), what the server can do is to add a route proxy at the application layer. According to various indications, this proxy may be called HTTP. sys Of course net. TCP Port Sharing Service is also suspicious.
After assuming that the proxy exists, the data receiving process should be like this: After a TCP link of the shared port is linked to the data packet, first, send the data packet to the proxy (just like the previous practice of TCP ), then the proxy should be the host header in the HTTP protocol based on the data in the TCP packet (that is, the website host header attribute set in IIS ), forward data to the website with the corresponding Host Header (more feasible is to send the socket handle of the TCP link to the corresponding website handler ), however, the proxy must analyze the data segments in TCP packets.
In addition, net. TCP should also have additional mark identification in the data area of TCP datagram, because we use the net. during TCP, the specified service endpoint property is similar to the Host Header setting in IIS. Of course, all the above are yy...

 

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.