Android IM practices and androidim practices

Source: Internet
Author: User

Android IM practices and androidim practices

IM (Instant Messaging) is widely used in Android. QQ, Wechat, Momo and other applications can be seen as IM real-time communication apps. Real-time communication is widely used in social apps, and its functions seem cool. Today, we will look at how the android IM software is implemented. Communication software such as IM, unless the company has great strength and energy, will be able to integrate such a framework on its own. For the majority of small and medium-sized software developers, the open-source framework is often considered. Opensource is a good news for developers and has played a significant role in pushing the entire software industry.
Openfire came into being in this environment, and as an open-source framework for real-time communication, it quickly became popular. Let's take a look at this open-source framework to save the universe, at the end of the article, we will use Openfire to make an AndroidAPP that can communicate in real time. If we combine the geographical location and then enhance the UI and interaction design, isn't it a stranger? YY after a while, I think it is quite interesting, soJust do it.

Openfire concept introduction CLICK: http://blog.csdn.net/ithomer/article/details/7192257
Openfire Official Website: http://www.igniterealtime.org/
Openfire installation documentation: http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html

1. Select a server

For real-time communication software, in addition to our clients, the server is critical. Because the server is a bridge connecting two sessions. According to the installation documentation, Openfire provides installation versions for multiple platforms. Windows, Linux/Unix. Therefore, the support is rich. For server selection, you can select your ECS, local PC, or Linux virtual machine. Skip this step if you select local installation.
To better meet the actual installation environment, I chose a local Linux virtual machine as the server environment. It is easy to deploy in the real server environment in the future.
Before proceeding to the next step, install mysql and java on the server.

2. Install openfire

Download the corresponding version from the official website. Here I select Openfire_3.9.3 Linux. After logging on to the server, use wget to download it.

Wget http://www.igniterealtime.org/downloadServlet? Filename = openfire/openfire-3.9.3-1.i386.rpm // install rpm-ivh openfire-3.9.3-1.i386.rpm with rpm after download is complete

After Openfire is installed, the openfire/directory is generated under the/opt directory.
After the installation is complete, you need to configure the database, according to the official documentation:

Make sure that you are using MySQL 4.1.18 or later (5.x recommended) ¹.Create a database for the Openfire tables:mysqladmin create [databaseName](note: "databaseName" can be something like 'openfire')Import the schema file from the resources/database directory of the installation folder:Unix/Linux: cat openfire_mysql.sql | mysql [databaseName]; Windows: type openfire_mysql.sql | mysql [databaseName];Start the Openfire setup tool, and use the appropriate JDBC connection settings.

Usemysqladmin create openfireCreate a database named openfire,cd /opt/openfire/resources/databaseGo to the openfire Database Resource Directory and usecat openfire_mysql.sql | mysql openfireImport the schema database file of openfire.

3. Start the Openfire Service

After rpm is installed, openfire automatically generates the openfire file in/etc/init. d/. You can open the service directly here.

Usage /etc/init.d/openfire {start|stop|restart|status|condrestart|reload}

Run the openfire service:/etc/init.d/openfire start, Run/etc/init.d/openfire statusIt indicates that the task is not running successfully.
View logcat /opt/openfire/logs, Displaynohup: cannot run command /opt/openfire/jre/bin/java: No such file or directoryIt seems that openfire cannot find java, so it cannot be started successfully, but our system does already have java installed, so we can solve it through soft link:

cd /opt/openfire/jre/bincp java java.bakrm javaln -s /usr/bin/java javaservice openfire start

After the soft link is complete, enable the openfire service again:

[root@iZ23572i0rtZ bin]# /etc/init.d/openfire statusopenfire is not running[root@iZ23572i0rtZ bin]# /etc/init.d/openfire startStarting openfire:[root@iZ23572i0rtZ bin]# /etc/init.d/openfire statusopenfire is running

Status: openfire is successfully started. Access port 9090 through the Virtual Machine ip address. This will jump to the setup interface. You can complete the configuration by Using setup.

After the configuration is complete, you can log on to your management console.

4. Integrate to Android

Since the Server installation is complete, we can start with our APP. The XMPP protocol library associated with Openfire is smack. After some exploration, we found that the ASmack library must be used to use Smack in Android. ASmack.
Based on instances, smack enables instant communication between two clients.

Attention
  • Internet permission must be added to AndroidManifest; otherwise, the connection fails.<uses-permission android:name="android.permission.INTERNET"/>.
  • When the client creates a chat with the client, the SID is username @ XXXX, XXXX indicates the server name, and here I am the ECS host name.
5. Github Repository

Https://github.com/gongmingqm10/SmackDemo

Related Article

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.