Whether it is a PC terminal or a mobile terminal, it is necessary to establish a double-ended connection to access the network to realize communication. Follow [Rongyun Global Internet Communication Cloud] to learn more

After the client and the server establish a connection, they do not disconnect, and then communicate (that is, send messages) through a long connection. In contrast, a short connection is to create a connection that is automatically disconnected after the program is executed.

Compared with the two, short connections frequently create and release connections, which consumes more resources. A long connection can avoid the overhead of creating a connection for each request, save time and consumption, and improve performance.

This article sorts out the content of the "IM Advanced Practical Master Class" on August 2, and analyzes and compares the evolution of common long-term connection protocols and long-term connection protocols to disassemble the design points of long-term connection protocols and the best practices of cloud integration.


Long connection FAQ

safety

The first is the security of transmission. Data transmission needs to be encrypted at the channel layer and the application layer, such as IPSec, TLS, PB, etc.

Secondly, it is also necessary to ensure the validity of the data and have the characteristics of anti-replay. Similar to the authentication of 5G terminals, vector verification is performed through SQN with timestamps to ensure data integrity and encryption. Finally, the abnormal client will be detected, and the client will be trusted through the dynamic authentication key.

(long connection security)

reliability

Including connection hold, fast reconnect and message reachability. The connection is maintained mainly through heartbeat keep-alive, weak network processing, and nearby access, etc., and a fast authentication reconnection strategy is designed to achieve low overhead, and QoS quality assurance ensures that messages are reachable.

(long connection reliability)

low overhead

The most fundamental of low overhead is to ensure that the size of the protocol packet is appropriate, reduce traffic consumption, and reduce power consumption when parsing the protocol packet. In addition, resource consumption is reduced in applications and data storage to obtain higher throughput and access numbers.

(long connection low overhead)


Design points of long connection protocol

The design points of the long connection protocol are actually mainly about how to achieve low overhead, security, reliability, and the scalability and completeness of the protocol.

(Key points of long connection protocol design)

Common long-term connection protocols in the industry are as follows:

Let's take a detailed look at the commonly used ones. SIP is a text protocol that supports TCP, UDP, and IPSec. It is more in line with international standards. , SIP phone, attendant console, its protocol design specifications and business specifications are all we can refer to.

XMPP is a text protocol, which is transmitted through XML. It has certain communication protocol specifications and is highly readable. It is mainly used in instant messaging systems, game platforms, collaborative spaces, and voice and video conferencing systems. The redundancy coefficient of this protocol is particularly high, which will bring relatively large traffic consumption.

MQTT is an open messaging protocol that is simple and easy to implement. The publish-subscribe model is adopted to publish one-to-many messages. Based on TCP/IP network connection, it provides orderly and lossless bidirectional connection. Compared with the above two protocols, its protocol package body is particularly small. 1-byte fixed header, 2-byte heartbeat message, minimize transmission overhead and protocol exchange, and effectively reduce network traffic.

The MQTT protocol is widely used in the Internet of Things, mobile Internet, intelligent hardware, Internet of Vehicles, electric energy and other fields.

Next, let's take a look at the scenarios or levels in which these protocols are generally applied.

First of all, if you want to make a call after the mobile phone is connected to the Internet, it will send data information related to the call or audio and video through GTP. If you need to invoke technical capabilities such as operators, some development capabilities will be invoked through XMPP or SIP. When building a cloud platform, it is necessary to have a long connection channel. Generally, there will be a navigation or configuration service to issue an address, and then connect to the long connection service through this address. The internal communication of the business is generally carried out through RPC, such as single chat, group chat, chat room and super group.

If you want to open up these capabilities, you need an open gateway to open the capabilities for some technologies of long-term connections.

Overall, the extensibility and completeness of common protocols are reversed.
SIP is mainly used in the field of telecommunications, and its completeness or design specifications of standard services are relatively high, and accordingly, its expansibility will be relatively insufficient.

Although the overhead of XMPP itself is relatively high, its business interface specification and logical model can be referred to.

The overhead of the MQTT protocol is relatively small, but the setup of its entire upper-layer business is not particularly rich.

From the perspective of evolution history, network evolution is basically an iteration every 10 years, and each stage will lead to different applications.

In order to solve the corresponding demand problems in different stages, the evolution of the transport layer protocol also has its stages.

The generation of UDP and GDP is basically at the same time, respectively guaranteeing the transmission rate and reliability. SCTP guarantees reliability while guaranteeing throughput. However, because its basic network is relatively stable, there are not many considerations for delay. Later, there is the QUIC protocol for low-latency multi-link data transmission.

Compared with the protocol of the transport layer, the change of the protocol of the application layer is not particularly big. Most of them were produced in the late 1990s and were used in different fields. For example, HTTP is mainly WEB, MQTT is mainly Internet of Things, SIP is mainly used in telecommunications, and XMPP is mainly instant messaging.


Rongyun long connection feature

Rongyun's long connection protocol mainly considers two aspects of efficiency and ease of use . Among them, the efficiency includes the comprehensive consideration of safety, reliability, completeness, scalability and low consumption design.

Security mainly ensures the security of channel transmission through channel encryption , but if an intermediate layer and a middleman are set up, it is necessary to encrypt the message body to ensure the reliability of data transmission; after ensuring the security of the transmission layer, it is also necessary to pass the dynamic key. and authentication code to ensure the security of client authentication ; the last is to ensure the anti-replay of data .

Reliability is to ensure the reliability of the circuit through the two-way heartbeat keep-alive between the client and the server; through the establishment of global network circuits, such as the establishment of dedicated lines between nodes, the client can access through a relatively reliable nearby address to ensure data transmission. The high efficiency and low delay of the application layer are then ensured by including QoS quality assurance, state delivery and weak network optimization .

In terms of completeness, Rongyun provides a variety of message types such as content and notifications, and a variety of business types such as single group chat, chat room, and super group. In addition, in order to ensure the efficiency of troubleshooting, Rongyun also serializes full-link messages on the protocol to track full-link messages.

In the design of the long connection protocol, Rongyun refers to the advantages and characteristics of common protocols in the industry. While ensuring low data transmission overhead , it also ensures scalability through custom message types, multi-level message channels, and custom business flows.

While ensuring high efficiency, the design of Rongyun long connection should also achieve ease of use through the characteristics of richness, multi-terminal, simplicity, expansion, and unity.

Rich services , such as single group chat, chat room, super group and other classic and emerging business types can be satisfied, and at the same time have the diversity of messages, including text, pictures, audio and video, emoticons and other message types and customization of other business scenarios information.

Multi- terminal coverage , native Android, iOS, cross-platform RN, Flutter and other full-platform coverage, to ensure the consistency of the protocol at each end, multi-terminal coverage and easy to iterate.

Multi-party unification ensures the unity of multiple terminals, and the technical capabilities of long-term agreements and the open capabilities of Rongyun communication services are unified.

Out of the box , the channel is simple and the protocol is concise.

High scalability , at the protocol layer to ensure the scalability of business setup.


融云RongCloud
82 声望1.2k 粉丝

因为专注,所以专业