How does the QQ message reach the receiver? After reading this you will understand

A sent a message to B in a different place through QQ, until B received the message, what kind of process did he experience in the middle?

A in Beijing sends a message to B in Shenzhen through QQ, and B receives the message on QQ. From the moment A clicks to send, to the end when B sees the message, how is the intermediate process realized? The middle may involve the conversion of message types, the role of QQ, ISP and other roles; the function of physical components or devices, the role of network cards, routers, network cables, and wires; signal conversion, etc. I don't just want to know how the seven-layer structure is realized, but how the whole process is realized, which may include network, communication, and physics-related knowledge. Ask professional teachers for advice, and hope that the teachers who understand will not hesitate to explain.

If all the servers of QQ are highly summarized as one server, the problem can be simplified as:

  • Communication between host A and QQ server
  • Communication between QQ server and host B

Host A (Xiao Ming) wants to send a message to the QQ server. Does host A (Xiao Ming) know the IP address of the QQ server?

There is no problem with this, the QQ server list is configured in advance in the QQ software.

Suppose host A (Xiao Ming) reaches the QQ server, what should the QQ server do at this time?

If host B (Xiaomei) is online, it will directly send the message to Xiaomei. However, the QQ server does not keep backups of the messages, which does not comply with the censorship norms.

If host B (Xiaomei) is not online, store it first, and then send the message to Xiaomei when Xiaomei is online.

Therefore, the QQ message can be sent regardless of whether the other party (receiver Xiaomei) is online or not, because this is purely a communication between host A (sender Xiaoming) and the QQ server.

Since the user's QQ message is to be stored, there is naturally a unique requirement for the user ID. The globally unique ID is the QQ number, which is the unique ID for identifying the user.

The QQ server can be regarded as a mail server. Each login user has a mail account (QQ number). The QQ server receives the user's message and saves the message in the database according to the recipient's QQ number. Once a message is to be extracted from the database, the message can be read out as long as the receiver's QQ number is used as the query condition.

Of course, it is impossible to have only one QQ server, but a list of multiple servers distributed in many places. This will be pre-configured in the QQ software. Host A (Xiao Ming) and which server to use first, you can try to ping the server list to see who has the smallest delay, and choose the best server first.

The host A (Xiao Ming) in Beijing and the host B (Xiao Mei) in Shenzhen may log in to not one but multiple QQ servers. Assume that it is server A that receives Xiao Ming's message, and Xiao Mei is logged on server B. How can server A know that Xiaomei is attached to server B, so that server A forwards the message to server B, and server B forwards the message to Xiaomei?

This requires a central server C. Whenever a user logs in to the server, the login server will send the user's QQ number and the server's IP address to the central server C, so that server C will have a QQ number and log in to the server correspondence table.

Server A only needs to query server C to obtain the IP address of server B, establish a secure encrypted connection, and then forward the message sent to Xiaomei to server B, and then forward it to Xiaomei.

After all, QQ belongs to instant messaging, and reducing the delay to a minimum is an important indicator. Therefore, in order to minimize the delay, the secure encrypted connection between the above servers has already been established before the arrival of the user message, and there is no need to spend additional time to establish it. Even the mapping table database between the user's QQ number and the server can be periodically synchronized from C to each QQ server.

The communication above uses IP packets as the means of transportation, and uses IP routing to find the destination, which are all common. The only thing to note is that the communication between the user and the QQ server requires NAT. In order for the QQ server to push messages to users in a timely manner, the NAT table must exist and cannot be aged and deleted because there is no traffic refresh, so that the QQ client cannot receive push messages in time.

In order to avoid the deletion of the NAT table, the QQ client will periodically send heartbeats to refresh the NAT table. The QQ server receives the heartbeat packet and throws away the heartbeat packet without almost any processing (update the user is still online).

As for QQ calling and QQ transferring files, the principles are similar, with only minor differences. The communication is completed end-to-end (connection establishment) between two clients, and the QQ server is needed as an intermediary to intervene. For QQ messages, there is no connection between the two clients at all, they only maintain the connection with the QQ server.

Author|Che Xiaopang talks about the Internet|Public account

Guess you like

Origin blog.csdn.net/zhynet000001/article/details/131701465