Smack implementing XMPP Instant Messaging--receiving messages

Source: Internet
Author: User

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

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.