XMPP-based openfire configuration installation + Android client implementation

Source: Internet
Author: User

Recently, I have been sorting out some materials in this area, so I 'd like to go straight to the topic without having to talk about it :)


I. XMPP-based openfire configuration and installation

1. download the latest openfire Installation File

Official download site:

Http://www.igniterealtime.org/downloads/index.jsp#openfire

:

EXE:

Http://www.igniterealtime.org/downloads/download-landing.jsp? File = openfire/openfire_3_7_1.exe

ZIP:

Http://www.igniterealtime.org/downloads/download-landing.jsp? File = openfire/openfire_3_7_1.zip

Here, openfire is a server, and there is also spark, which is an IM software for XMPP protocol communication chat CS. It can be used for chat and conversation through openfire.


2. After the download is complete, if you download the EXE file, execute your installation file and install it. Here I am a zip file. After decompression, copy the openfire directory to the C: \ Program Files \ directory, which must be in the c: \ Program Files \ directory. Then the openfire installation is complete.

3. Start the openfire server and configure it. Open the openfire.exe file in the c: \ Program Files \ openfire \ bindirectory. Double-click the file and run it.

4. Click the launch admin button to go To the http: // 127.0.0.1: 9090/Setup/index. jsp page and configure the openfire server.

 

5. Select the Simplified Chinese Language

Click continue to enter

 

6. Configure the server Domain Name

For local access, you do not need to modify or use localhost or 127.0.0.1.

If you are using Internet or LAN access, configure your address as an Internet or LAN address.

 

7. Select a database

Choose the built-in openfire. Of course, you can also choose your database type. Such as Oracle, SQL Server, and MySQL. If openfire does not have a JDBC connection driver, you need to add a JDBC driver to connect to the database. The driver is stored in the c: \ Program Files \ openfire \ lib directory.

 

8. Select the feature configuration. The default value is enough.

 

9. Administrator email. skip this step.

 

10. Installation Complete

Go to the Administrator console page

 

11. Go to the http: // 127.0.0.1: 9090/login. jsp page and enter the admin and password to log in.

 

12. You can see

The server name is the connection address of WeChat chat. You can use the spark or WeChat Chat link for IM communication and chat ......

So far, openfire installation and configuration have been completed. The next article begins to complete the installation and configuration of WeChat chat.

II. Implementation of the android Client

First, browse the project structure and start to parse the code one by one:

The main code is attached, and the last is

@ Overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. formclient); // get the user name passed by intent this. puserid = getintent (). getstringextra ("userid"); listview = (listview) findviewbyid (R. id. formclient_listview); listview. settranscriptmode (listview. transcript_mode_always_scroll); this. adapter = new myadapter (this); listview. setadapter (adapter );// Get text information this. msgtext = (edittext) findviewbyid (R. id. formclient_text); this. PB = (progressbar) findviewbyid (R. id. formclient_pb); // message listening chatmanager CM = xmpptool. getconnection (). getchatmanager (); // send a message to the water-PC Server (get your server and Friends) // final chat newchat = cm. createchat (this. puserid + "@ water-PC", null); Final chat newchat = cm. createchat ("Lee @ water-PC", null); Final chat newchat1 = cm. createchat ("chai @ water- PC ", null); Final chat newchat2 = cm. createchat ("Huang @ water-PC", null); cm. addchatlistener (New chatmanagerlistener () {@ overridepublic void chatcreated (chat, Boolean able) {chat. addmessagelistener (New messagelistener () {@ overridepublic void processmessage (chat chat2, message) {log. V ("-- tags --", "-- tags-form --" + message. getfrom (); log. V ("-- tags --", "-- tags-message --" + message. getbody (); // receive If (message. getfrom (). contains (puserid + "@ water-PC") {// obtain the user, message, time, instring [] ARGs = new string [] {puserid, message. getbody (), timerender. getdate (), "in"}; // display the message android in handler. OS. message MSG = handler. obtainmessage (); MSG. what = 1; MSG. OBJ = ARGs; MSG. sendtotarget ();} else {// message. getfrom (). cantatins (retrieve users, groups, and manage messages on the list); // obtain users, messages, times, instring [] ARGs = new string [] {Message. getfrom (), message. getbody (), timerender. getdate (), "in"}; // display the message android in handler. OS. message MSG = handler. obtainmessage (); MSG. what = 1; MSG. OBJ = ARGs; MSG. sendtotarget () ;}}) ;}}); // attachment button btattach = (button) findviewbyid (R. id. formclient_btattach); btattach. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view arg0) {intent = new intent (formclient. this, Formfiles. class); startactivityforresult (intent, 2) ;}}); // send the message button btsend = (button) findviewbyid (R. id. formclient_btsend); btsend. setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {// get text string MSG = msgtext. gettext (). tostring (); If (MSG. length ()> 0) {// send the message listmsg. add (new MSG (puserid, MSG, timerender. getdate (), "out"); // refresh the adapter. notifydatasetchanged (); try {// send The message is sent to xiaowangnewchat. sendmessage (MSG); newchat1.sendmessage (MSG); newchat2.sendmessage (MSG);} catch (xmppexception e) {e. printstacktrace () ;}} else {toast. maketext (formclient. this, "enter information", toast. length_short ). show ();} // clear textmsgtext. settext ("") ;}}); // accepts the file filetransfermanager = new filetransfermanager (xmpptool. getconnection (); filetransfermanager. addfiletransferlistener (New recfiletrans Ferlistener ();} @ overrideprotected void onactivityresult (INT requestcode, int resultcode, intent data) {super. onactivityresult (requestcode, resultcode, data); // send the attachment if (requestcode = 2 & resultcode = 2 & Data! = NULL) {string filepath = data. getstringextra ("filepath"); If (filepath. Length ()> 0) {sendfile (filepath );}}}

Finally, you cannot forget the project code. The address is:

Http://download.csdn.net/detail/sky_monkey/5820879


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.