P2P point-to-point technology for UDP Intranet penetration

Source: Internet
Author: User
We recommendProgramDedicated search engine-http://www.openso.net

Point-to-point technology has been widely used in recent years, mainly represented by QQ, Skype, BT, Thunder, PPStream, PPLIVE, qvod. We can see that as long as the data volume is large, and the use of transit servers requires a certain amount of input applications, we can consider using P2P technology. There are two benefits: 1. It can reduce costs and investment. 2. Improve transmission performance.
There are a lot of materials on the Internet about how to penetrate the Intranet to achieve point-to-point communication between the Intranet, but it is uneven. Many people may still be able to see it, but it is not difficult to understand it, the key to the difficulty lies in understanding some basic knowledge, which involves some network communication principles. In general, we will first consider using TCP to implement network programs. The main advantages of using TCP are as follows: 1. programming is simple, most of the C-S model is used, that is, the client to the server. 2. TCP features ensure the reliability of data transmission. As long as the Protocol is customized properly, there will be basically no packet loss and boundary issues. However, TCP also has a disadvantage, that is, low communication efficiency.

From the above description, we can draw two conclusions that P2P applications must solve at least two problems:1. Implement Network Communication between machines in the intranet. 2. Solve the Problem of unstable data transmission over UDP.

first, let's talk about the first point: Intranet penetration. Assume that a 192.168.1.77: 8000 after nat211.133. * is directed to 192.168.1.88 after nat211.134: 9000 send data. Suppose you send data to 211. 134. * If a packet is sent directly from port 9000 of the IP address, the packet is discarded as an invalid or invalid packet after it reaches nat211.134. *. Nat is equivalent to a firewall at this time, data packets that do not have a valid session are not transmitted. Of course, you cannot directly use the Intranet address 192.168.1.88 to send data packets. This is like if you want to call somewhere in Shanghai in Guangzhou, it is silly to call a region directly.
how can we achieve penetration? First, we need to know the NAT device. The Nat English spelling is network address translator (network address converter). To put it bluntly, it is all the packets sent through NAT, all requests are forwarded through port translation instead of using the original port. In other words, communication between the Intranet and the Internet is not directly performed by the Intranet machine and the Internet Nat, instead, you can use the Intranet to create a session for the Internet Nat. Based on the session, Nat is divided into two types: elastic Ric napt and cone napt. In short, the symmetric napt is a dynamic port ing Nat, while the cone napt is a static port ing Nat. Currently, most of the consumers on the market belong to the latter. cone is a cone of English meaning that a port can communicate with multiple external NAT devices. This is exactly what we want for point-to-point penetration. Otherwise, most of the point-to-point software will not work normally.

As in the preceding example, communication is required between nat211.133. * And nat211.134. *, but data packets cannot be sent directly at first. We need a man in the middle. This is the external Index Server (we assume it is 211. 135. *: 7000), when nat211.133. * to 211. 135. *: 7000 sends data packets, 211. 135. *: 7000 indicates that data can be normally received because it is an open service port. When 211. 135. *: 7000 after receiving the data packet, you can obtain the temporary session information of nat211.133. * for external communication (this temporary port is assumed that 6000 will expire and the specific time is different, however, in my personal test, a heartbeat packet is sent every 30 seconds to ensure that the port maintains the Communication Connection continuously. The Indexing Server should save this information at this time. At the same time, nat211.134. * also sends a heartbeat packet to the Indexing Server at any time, and the indexing server sends a notification to nat211.134. * to send it to nat211.133 .*: 6000 send a test packet (this packet should have more than one packet). nat211.133. * Send a feedback packet to the Index Server after receiving the notification packet, indicating that you have sent a test packet to nat211.133. *: 6000, the indexing server then forwards the feedback packet to nat211.133. * after receiving the feedback packet, nat211.133. * after receiving the data packet, the indexing server sends the data packet to the originally requested nat211.134. *, and the connection is connected, for penetration, nat211.134. * forwards the information to port 9000 of 192.168.1.88.
In the case of hybrid Ric napt, some people on the Internet say they can use the port probe method, but the success rate is not high. I suggest using a server for transit. In addition, it is best to check whether the same Nat is performed before the packet is sent, that is, the Intranet is sent over the Intranet. If yes, the packet can be sent directly without going back through the Internet.
Second, we will solve the problem of unstable UDP transmission. In fact, this involves another aspect of knowledge, that is, sliding windows. We can open a buffer for receiving and reorganizing data cyclically, in addition, the timeout and re-transmission mechanism and the confirmation mechanism are a bit like the TCP transmission principle. However, if the processing is good, the efficiency is definitely higher than the TCP method. In addition, I will not talk about the sliding window mechanism here. If you are interested, you can search for information online.

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.