Smack implements XMPP Instant messaging, which has been introduced in the previous blog post!
About receiving messages
Online blog about the corresponding
1, Smack API Learning http://314858770.iteye.com/blog/908246
2, Smack development Demo---Send and receive messages http://blog.csdn.net/majian_1987/article/details/9474027
The above 2 blogs all have their own description of the problem, but in the real beginning to use the time, found that the code is not too able to pass, you debug a version of their own, record
Java code:
Package Ceshi2;import Org.jivesoftware.smack.chat;import Org.jivesoftware.smack.chatmanagerlistener;import Org.jivesoftware.smack.messagelistener;import Org.jivesoftware.smack.xmppconnection;import Org.jivesoftware.smack.xmppexception;import Org.jivesoftware.smack.packet.message;public class Ceshi2 {public static void Main (string[] main) throws xmppexception{//Set server address Xmppconnection conn = new Xmppconnection ("127.0.0.1"); Conn.connect (); Enter account number and password login conn.login ("Yixin", "Yixin"); Setup information for monitoring final MessageListener messagelistener=new MessageListener () {@Overridepublic void ProcessMessage (Chat arg0, Message message) {//TODO auto-generated method stubstring messagebody = Message.getbody (); System.out.println ("received message:" +messagebody);}; Chatmanagerlistener chatmanagerlistener=new Chatmanagerlistener () {@Overridepublic void chatcreated (chat chat, Boolean arg1) {//TODO auto-generated Method Stub Chat.addmessagelistener (MessageListener);}}; Conn.getchatmanager (). Addchatlistener (ChatmanAgerlistener); while (true); Dead loop, maintain the connection without interruption//exit login//conn.disconnect (); }}
Note: The rest of the articles can be consulted blog
1. Introduction and use of smack class library based on XMPP openfire smack development [2]
http://blog.csdn.net/shimiso/article/details/8816540
2. Introduction and use of smack class library based on XMPP openfire smack development [1]
http://blog.csdn.net/shimiso/article/details/8816558
Smack implementing XMPP Instant Messaging--receiving messages