The company has nothing to do. The team lead told me to write a demo and I was so dizzy ....
Let's talk about this chat room first, and let's talk about the server. It's a typical example. It uses the finished openfire. Smack: This is a jar file and library used in javae. To use this package on Android, you need to use the asmack package. This can be found on the official website. In fact, there is no difference between the inside and the smack package. At present, I have not found the specific difference.
Some friends may say what this smack is for. In my personal words, a rack package already packed with XMPP protocol. Provides API operations...
1. First, to enter the chat room, you must first know the Conference Service (using spark) where the chat room is located)
/*** Initialize the chat service meeting list */private void inithostroom () {collection
2. Get the jid of the service before you can go to the meeting list:
/*** Initialize the room list */Public void Init () {listdiscoveritems = new arraylist <discoveritems. item> (); // obtain servicediscoverymanagerservicediscoverymanager related to xmppconnection. discomanager = servicediscoverymanager. getinstancefor (constants. conn); // obtain the project of the specified XMPP object // This example obtains the project discoveritems discoitems related to the online Directory Service; try {discoitems = discomanager. discoveritems (jid); // obtain the iterator it = discoitems of the XMPP object to be viewed. getitems (); // displays the project while (it. hasnext () {discoveritems. item = (discoveritems. ITEM) it. next (); system. out. println (item. getentityid (); system. out. println (item. getname (); listdiscoveritems. add (item) ;}} catch (xmppexception e) {e. printstacktrace ();}}
3. Similarly, to enter the meeting room (chat room), you must obtain its ID to enter
// The service name must be the service jid = getintent () created in the room (). getstringextra ("jid"); try {muc = new multiuserchat (constants. conn, jid); // create a chat room and enter the room's nick name (nickname) MUC. join ("tests"); log. V (TAG, "Join success");} catch (xmppexception e) {e. printstacktrace ();}
Easy!
Well, this article is here, and the next is some internal processing in the chat room.