Android im Practice

Source: Internet
Author: User

IM (Instant Messaging) is widely used in Android. Qq,wechat, MO Mo and other applications can be regarded as IM real-time communication app, real-time communication in social applications, the use of a wide range, its function seems to be more cool. Today we will look at how the Android IM software is implemented. like IM this implementation of communications software, unless the company has a relatively large strength and energy, will be to the entire framework of such a set. For the majority of small and medium-sized software developers, think more is open source framework. OpenSource is a boon for developers, and it is a driving force for the entire software industry.
OpenFire in this environment came into being, and as a real-time communication open source framework quickly became popular, the following we come together to learn such an open-source framework to save the universe, the end of the article will use OpenFire to make a real-time communication Androidapp, If the combination of the geographical location and the multi-point UI and interactive design promotion, this is not mo mo? YY for a while, think very interesting, then Just do it .

OpenFire Conceptual Introduction Please 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 Server

For real-time communication software, in addition to our clients, the server side is more critical. Because the server is a bridge connecting two sessions. Depending on the installation documentation, OpenFire provides a version of the installation for multiple platforms. Windows, Linux/unix. So the support is still very rich. As for the choice of servers we can choose our own ECS, local PC, or Linux virtual machine. To select a native installation, skip this step.
To better match the actual installation environment, I chose the local Linux virtual machine as the server environment. It is easy to deploy to a real server environment later.
Install MySQL and Java on the server before you proceed to the next step.

2. Install OpenFire

Download the corresponding version from the official website, I choose openfire_3.9.3 Linux version here, log into the server directly using wget download

wget http://www.igniterealtime.org/downloadServlet?filename=openfire/openfire-3.9.3-1.i386.rpm//下载完成后使用rpm进行安装rpm -ivh openfire-3.9.3-1.i386.rpm

OpenFire The Openfire/directory is generated in the/OPT directory when the installation is complete.
After the installation is complete, the database configuration is required, according to the official documentation:

Make sure is the using MySQL 4.1.18 or later (5.x recommended) 1. Create a database  for the OpenFire tables:mysqladmin Create [DatabaseName] ( Note: "DatabaseName" can 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.

Start by mysqladmin create openfire Creating a database named OpenFire, cd /opt/openfire/resources/database enter the OpenFire database resource directory, and use cat openfire_mysql.sql | mysql openfire the schema database file to import OpenFire.

3. Start the OpenFire service

Using RPM, the OpenFire will automatically generate OpenFire files in/etc/init.d/and you can open the service directly here.

{start|stop|restart|status|condrestart|reload}

Run the OpenFire service: /etc/init.d/openfire start The run /etc/init.d/openfire status display did not run successfully.
Looking at log cat /opt/openfire/logs , nohup: cannot run command /opt/openfire/jre/bin/java: No such file or directory it appears that OpenFire cannot find Java, so it cannot start successfully, but our system has already installed Java, so it can be solved by the soft chain:

cd-s /usr/bin/java javaservice openfire start

Once the soft chain is complete, turn on the OpenFire service again:

[root@iZ23572i0rtZ bin]# /etc/init.d/openfire statusisnot running[root@iZ23572i0rtZ bin]# /etc/init.d/openfire startopenfire:[root@iZ23572i0rtZ bin]# /etc/init.d/openfire statusis running

Status shows that OpenFire has successfully started. Access to port 9090 via the virtual machine IP will jump to the Setup interface, and the configuration can only be done via setup.

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

4. Integrate to Android

Now that the server installation is complete, we can start our app. The client XMPP protocol library associated with OpenFire is smack. After groping, it was found that the Asmack library must be used in order to use smack in Android. Asmack.
As an example, the real-time communication between two clients is realized through smack.

Attention
    • You must add the Internet permission in Androidmanifest or the connection fails. <uses-permission android:name="android.permission.INTERNET"/>.
    • When the client creates a chat to the client, the SID is [email protected], XXXX is the server name, I am the ECS host name.
5. Github Repository

Https://github.com/gongmingqm10/SmackDemo

Android im Practice

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.