Simply put, TCP and UDP Holes

Source: Internet
Author: User

1. TCP communication:

There are now two computers A and B. In

Assume that the address of a is 192.168.0.100.

Assume that the address of B is 192.168.0.102.

A wants to send a string hello to B. If TCP is used between A and B, what is the process for B to receive hello?

First, establish a connection (after three handshakes are successful, the links between A and B are considered successful), and then a sends data to B.

 

If A and B are not in a LAN, the communication between A and B needs to be implemented.

Assume that a accesses the Internet through vros1 S1. B accesses the Internet through vros2 S2.

Internet IP address of S1: 114.66.5.211 local IP Address: 192.168.0.1

S2 Internet IP Address: 14.153.27.47 local IP Address: 192.168.1.1

Local Address of A: 192.168.0.100

Local Address of B: 192.168.1.102

 

Do not talk about the communication between A and B for the moment. Let's talk about a accessing www.baidu.com

The source address is 192.168.0.100, and the target address is 61.135.169.105 (www.baidu.com address after DNS resolution ).

Because a does not have the 61.135.169.105 address in the network, data is sent to the default gateway. The default gateway address here is 192.168.0.1 (local address of router S1)

What will be done after vros1 S1 obtains the data?

He will perform Nat ing and then replace the previous source address 192.168.0.100 with the Internet IP address 114.66.5.211.

How is it mapped?

It converts 192.168.0.1: 22124 to an Internet port number. Assume that the port number to be converted is 1481.

22124 indicates the port from which computer A sends the request. 1481 is the value calculated by the vro. You do not need to know the specific calculation method. You only need to know that the value is unique in the NAT table.

See the following table:

 

The source IP address sent to the Baidu server is 114.66.5.211: 1481. The target IP address is 61.135.169.105: 8080. After receiving the request, Baidu changes the source IP address to the target IP address to send data.

The final data will be uploaded to the routers S1. after the data is uploaded to the routers, it starts to query the NAT table based on the port number. If the port number exists in the table, the SRC value is taken out and the destination address in the data is

Replace it with the SRC value. In this way, a receives data from the Baidu server.

 

According to this idea, we can conclude that to communicate with a and B, the S1 of the router must know the ing between B and S2. Similarly, vros2 s2 must know the ing of A in S1.

The common practice is to use a server T, A and B to access the server T, then t will get the ing between A and B in their respective routers, then, send the ing of B in vros2 S2 to S1.

Send the ing of A in Router S1 to S2. then A and B can communicate directly.

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.