Mobile Application (mobile app) Development IM chat program Solution

Source: Internet
Author: User

This solution has been customized for a long time and has been busy for some time. Recently, I am a little bit better and don't have to work overtime. So let's take the time to sum up and share it with you, which is a reference for everyone! Maybe this is not the best solution, but as long as the best solution can meet the current needs, it is also the best solution. Who said no! O (distinct _ distinct) O ~

 

The solution is as follows:

First look at the figure

The process is as follows:

The mobile phone sends chat content to the PC.

1. The mobile phone program connects to the server's ServerSocket through Socket

2. The server then parses the standardized messages or chat content sent by the Mobile client.

3. the parsed content is then forwarded to the openfire server using the smack framework.

4. The openfire server sends chat information to the client (BS, CS, and PhoneClient. The client can be a browser on a pc, desktop applications on a pc, and mobile applications.

5. The persistent connection of the BS program of the PC Client (listener using http bind) listens to the data sent by the openfire server, which is directly displayed on the page.

 

Similarly, the PC Client sends chat content to the mobile phone end.

1. The PC Client (BS) can directly send chat data to the openfire server using http bind (the persistent connection mode of http requests provided by xmpp;

2. When the openfire server receives the chat content, there is a chat content listener in the smack framework of the socket server.

3. After listening to the content sent from the PC end to openfire, the socket will be used to send the defined message or chat content to the mobile phone end.

4. the socket on the mobile phone end will not stop polling (the heartbeat persistent connection mode can be simulated) to determine whether a message has arrived. If yes, it will be displayed.

 

The process of a common chat program is that the client sends messages to the openfire server, and the openfire server forwards messages to other clients. Why should we add the socket server while saving the socket server?

We have our own principles for doing this:

First, if you want the mobile terminal to implement the Code to send programs to the openfire server, the workload is quite large. Because each Mobile Phone platform uses different languages, each platform needs to send chat messages to the openfire server. This is actually a repetitive job, and the technology that each platform sends messages to a mobile phone will allow developers on each mobile phone to learn a set of code to interact with openfire. This will inevitably repeat the code of the same business. Therefore, it is also advantageous to put the code in a tcp/ip socket transfer server for unified sending.

Second, if messages are sent on the socket server, the service can be processed and filtered in a unified manner.

 

Solutions rejected by mobile phones for Reference

The mobile phone end uses the http persistent connection method. This is not feasible.

1. The mobile network of the mobile phone is unstable, and persistent connections are often disconnected. Of course, you can automatically reconnect the mobile phone.

2. Persistent connections are always connected to the server, occupying server resources. Of course, you can use the heartbeat persistent connection or polling method.

Third, the mobile phone client will always connect to the server and use the network bandwidth traffic of the mobile phone user (the traffic is not free, what do customers think)

4. The mobile phone end has been connected to the server, which also consumes the power of the mobile phone (currently, the smart machine solves the power problem)

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.