Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the IM SDK link optimization strategy?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you what the IM SDK link optimization strategy is, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Overview

In the field of instant messaging, the arrival of messages must be timely. In the current mobile Internet environment, mobile devices face many problems, especially because the base station continues to switch with the movement of the equipment, which will lead to signal instability, resulting in communication quality is difficult to guarantee. Therefore, under the unstable network condition, how to detect the network health status, reconnect in time to ensure the stability of the link, and finally achieve no user perception in the case of network jitter is a difficult problem faced by many technicians.

Complex network conditions

1. DNS problem

1) the service is not available due to DNS hijacking or failure

2) performance degradation due to inaccurate DNS scheduling.

Principle of DNS hijacking or failure

2. Weak network problem

1) in elevators, mountain areas or remote areas, the network is weak due to the lack of base station coverage in some areas.

2) the weakness of the network caused by other signal interference.

Solution method

1. Link strategy

Link policy architecture

2 、 HTTPS

HTTPS, the HTTP protocol, adds a layer of SSL protocol encryption, while the SSL certificate follows the SSL protocol. It is issued by the trusted digital certificate authority CA after verifying the identity of the server. The issued certificate is generally placed in the root directory of the server as the public key, so that the client request can be returned to the client. The private key is stored in the internal center of the server to decrypt the public key.

HTTPS architecture diagram

Security:

1) use HTTPS protocol to authenticate users and servers to ensure that data is sent to the correct clients and servers

2) HTTPS protocol is a network protocol built by SSL+HTTP protocol for encrypted transmission and identity authentication, which is more secure than HTTP protocol. It can prevent data from being stolen and changed in the process of transmission, and ensure the integrity of data.

3) HTTPS is the most secure solution under the current architecture, although it cannot guarantee absolute security, it greatly increases the cost of man-in-the-middle attacks and can solve the problems related to network hijacking.

3 、 HTTPDNS

Traditional DNS parsing:

The complete resolution process of DNS is very long. First, the IP address is obtained from the local system cache. If it cannot be obtained from the nearest DNS server, but still cannot be obtained, it needs to be obtained from the main domain name server. Each layer has a cache, but for the real-time performance of domain name resolution, each layer of cache has expiration time. This DNS resolution mechanism has several shortcomings:

1) if the cache time is set long, the domain name will not be updated in time. If it is set short, a large number of DNS resolution requests will affect the request speed.

2) Domain name hijacking is easy to be attacked by middlemen or hijacked by operators. According to statistics, when domain names are resolved to third-party IP addresses, the hijacking rate will be as high as 7%.

3) the DNS parsing process is out of control, and the fastest IP cannot be guaranteed.

4) only one domain name can be resolved at a time.

After using HTTPDNS:

1) Domain name resolution is separated from requests. All requests use IP addresses directly without DNS resolution. App periodically requests HTTPDNS servers to update IP addresses.

2) ensure the security of HTTPDNS request and avoid being hijacked by signature and other methods

3) DNS parsing is controlled by yourself, which ensures that the nearest IP address of the user's location is returned, or the fastest IP is used according to the speed measurement results of the client.

4) multiple domain names can be resolved with one request

5) secure and accurate resolution results: access the server using HTTP protocol to obtain the domain name resolution result, bypass the operator's Local DNS and avoid domain name hijacking; HTTPDNS can directly obtain the client's egress gateway IP, thus more accurately judging the client region and operator, and getting more accurate resolution results.

4. Compound link

Composite connections, that is, multiple connections. It solves the problem of connection selection of multiple IP addresses, and selects the fastest and optimal IP address according to the current region and network conditions.

Let's take two IP returned by domain name query as an example to introduce the process:

1) the two IP will attempt to establish a connection in order. If the first IP returns a failure, the connection to the second IP will start immediately.

2) if the first IP returns successfully, the second IP will be added to the connection attempt list and all attempted connections will be stopped

3) if the first IP fails, the connection to the second IP will be started immediately

4) if the first IP is in pending state, a timer will be started. The default delay of 2s will initiate the connection of the second IP, and if there are multiple IP, the connection will be recursive.

5. Intelligent heartbeat

Factors that affect the longevity of TCP long connections:

1) NAT timeout

Most mobile wireless network operators will eliminate the corresponding items in the NAT table and cause link interruption when there is no data communication after the link for a period of time. NAT timeout is an important factor affecting the life of TCP connections (especially in China), so the client automatically calculates the NAT timeout to dynamically adjust the heartbeat interval, is an important optimization point.

2) the lease term of DHCP (lease time)

Current tests have found that Android's handling of DHCP has a Bug,DHCP lease that will not be renewed voluntarily and will continue to use expired IP, a problem that can cause occasional disconnection of TCP long connections.

3) change of network state

Mobile phone network and WIFI network switching, network disconnection and reconnection will cause changes in the network state, resulting in a long connection into an invalid connection. It is necessary to listen to the network status change events and re-establish the long connection.

Heartbeat strategy:

Different heartbeat strategies should be chosen according to different operators and network status.

1) differentiated processing between foreground and background

In order to ensure the timely experience of receiving messages, a fixed heartbeat is used when the application is active in the foreground. When the application enters the background (or the foreground closes the screen), it first uses the minimum heartbeat to maintain a long link, and then enters the background to calculate the adaptive heartbeat. The purpose of foreground and background differentiation processing is to select the time period in which the user is not active as far as possible, so as to reduce the problem of message delay collection caused by heartbeat calculation and the power consumption caused by frequent heartbeat application.

2) adapting to different network strategies

Usually, in order to ensure security, the network policies configured in different office areas are different. In order to adapt to this situation, SDK can intelligently detect the time interval of heartbeat and ensure the stability of the link.

3) redundant heartbeat

When the user lights up the screen, make a heartbeat; when switching to the foreground, make a heartbeat; when networking, rebuild the signaling TCP, do a heartbeat.

The above content is what is the IM SDK link optimization strategy? have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report