Chat about Android message push in instant messaging development

When we discuss push on Android phones, most of the cases are talking about integrating third-party push, because even a big manufacturer like WeChat needs to be added to the startup whitelist to stay online.

In this way, the push of domestic mobile phones has become a problem and an opportunity.

 

How to implement push

Summarize several push implementation methods, some of which we only need to understand, because they are historical solutions and have now been abandoned.

polling

The client periodically asks the server if there is any new message. The biggest disadvantage of this method is the contradiction between performance and real-time performance. Too long or too short polling time is not good.

Short message

This method is not allowed before it is born. First, the operator will not cooperate, and secondly, intercepting mobile phone text messages is a high-risk permission, and most users will not pay for it.

Long even

The most common solution at present is that the client and the server establish a long TCP connection, send heartbeat packets regularly to keep alive, and the server pushes new messages through the long connection channel.

Here is a brief description of the long connection and the heartbeat package. A long connection is that after the connection is established, the two parties send data to each other, and they do not actively disconnect after sending.

However, in some cases, the long connection will be disconnected. The problem lies in the disconnection, and this must be known by the client, because the client can reconnect to the server, but the server cannot contact again. client. In this way, it is determined that the heartbeat packet must be sent by the client to the server. So the role of the heartbeat packet is to tell the server that the client is still alive. If the server hangs, the client can know, so keep alive means to keep both sides alive. Instant messaging chat software app development can add Weikeyun's v:weikeyyun24 consultation

 

NAT timeouts are a typical example of some of the situations mentioned above. Because of the limited amount of IPv4 IP, the IP assigned by the operator to the mobile terminal is the IP of the operator's intranet. To connect the mobile phone to the Internet, a network address translation (NAT) needs to be done through the operator's gateway. Simply put, the operator's gateway needs to maintain a corresponding relationship between the external network IP, port to the internal network IP, and port to ensure that the mobile phone on the internal network can communicate with the Internet server. Most mobile wireless network operators will eliminate the corresponding entry in the NAT table when there is no data communication on the link for a period of time, causing the link to be interrupted. Therefore, the long-connection heartbeat interval must be less than the NAT timeout time (aging-time). If the heartbeat is not performed after the aging time, the TCP long-connection link will be interrupted, and the server will not be able to send messages to the client. It can only wait until the client next time. After the heartbeat fails, the connection can be reestablished to get the message.

With the long connection, even in sleep mode, a push message can wake up the Android system. This is determined by the system mechanism. We only need to know the conclusion here.

Pushed metrics

There are several core metrics to consider when accessing push services.

online rate

Online rate = number of online users / total number of users.

The method to keep the push service background online:

    The Push process is resident in the background, and the user needs to manually make the application resident;
    the way of sharing the connection channel, such as Jiguang or a push, through the shared connection, when the application arrives with a push, the application is awakened.


Obviously, the latter is closer to GCM in experience.

arrival rate

Reach rate = actual number of arrivals / number of target users

Online number -> number of target users -> number of successful delivery, these two data will be inaccurate if there is a problem with the back-end calculation or call;

Online number -> actual number of arrivals -> number of impressions. After the data is received, whether to display it depends on whether the user has turned on the switch to allow notifications of the application, which can be judged by the following methods:
    
notificationManagerCompat.areNotificationsEnabled();

power consumption

Power consumption is affected by many aspects. If you receive a lot of push notifications and open applications more frequently, the power consumption will naturally increase a lot, but this user is acceptable.

The following power consumption factors are more disgusting to users:

    The power consumption caused by mutual wake-up between applications, because this power consumption belongs to other applications, and the user has no intention to open it;
    the power consumption caused by error retry, the optimization of the retry strategy includes the accumulation and reset of the retry time.

Push selection

As mentioned above, the push we are talking about here is a third-party push, so some developers have to ask, why not do the push yourself?

It's not impossible to do it yourself, but there are a few things to consider:

    The development cost issue, whether the ROI is acceptable;
    if you don't join the whitelist, once the application is completely killed, no one will sing the resurrection magic for you (arouse each other).


The third-party push mainly includes manufacturer push and non-manufacturer push:

    Huawei, Xiaomi, Meizu push;
    Getui, Jiguang, Youmeng;
    Ali, Tencent, Baidu.


Among them, several factors for selection:

    Whether the manufacturer's push notification is a system channel (supported by all manufacturers);
    whether the manufacturer's push transparent transmission is a system channel (Meizu only);
    the market share of non-manufacturer push notifications (affects the probability of shared connections evoking each other).

Guess you like

Origin blog.csdn.net/wecloud1314/article/details/126699451