Smack 4.1.2+openfire 3.10.2i

Source: Internet
Author: User

OpenFire and previous versions of the configuration does not have much difference is not detailed introduction, online search will have a lot of illustrations

The following main talk about the development and use of smack 4.1.2, on the internet to read a lot of articles including StackOverflow are not more than 4.1 of the use of instructions, and I found that some official notes do not seem to correspond with this version, such as using Connectionconfiguration#setreconnectionallowed (Boolean) to turn on/off this feature, I checked the method at all, so I wrote some notes on my own, For your reference, at the same time to discuss the promotion of the use of smack the latest version.

Here are the links I refer to
http://my.oschina.net/yuanxulong/blog/348572
Https://github.com/igniterealtime/Smack/blob/master/documentation/gettingstarted.md
http://blog.csdn.net/chszs/article/details/41620843
http://blog.csdn.net/chszs/article/details/41620853
Securty problems
https://issues.jenkins-ci.org/browse/JENKINS-25505
Authentication method
http://blog.csdn.net/coding_me/article/details/39524137
0 Certified Solutions
I have solved this problem, the Service Name should is the same as OpenFire settings:



Below is I write the tool class, chats also mainly two things, one is sends the message, one is accepts the message, sends is smacktools.getchat (); SendMessage ("detail") gets the content is Chatmanager.addchatlistener (new Chatmanagerlistener () that part, generally speaking relatively simple, Here are a few notes to note
(1) The following is the code after Securtymode closed
(2) servername is not the name of the OpenFire server
(3) host can change in the host file
(4) Connect.login () must be looped or otherwise displayed as offline in others
(5) newchat = Chatmanager.createchat ("[Email protected]", null); @ behind is servername
(6) You must close the connection when you are finished using the phenomenon of sending a multi-bar display appears. Because each conversation is a single thread
(7) The use of the loop to get the other side of the content of the speech to obtain content and ensure that the online, like the network said that the installation of the re-linked method in this version does not exist


public class Smacktools {


public static Smacktools Smacktools;

private Abstractxmppconnection Connection;

Private String content;

Private Chat Newchat;

Private Smacktools () throws interruptedexception{
Xmpptcpconnectionconfiguration.builder Builder = Xmpptcpconnectionconfiguration.builder ();
Builder.setsecuritymode (ConnectionConfiguration.SecurityMode.disabled);
Builder.setusernameandpassword ("Why1", "why134134");
Builder.setservicename ("why-pc");
Builder.sethost ("csdn.shimiso.com");
Builder.setconnecttimeout (10000000);
Builder.setresource ("why");


connectionconfiguration config = Builder.build ();
try {
Connection = new Xmpptcpconnection (Builder.build ());
Connection.connect ();
Connection.login ();

Get the Conversation
Chat
Final Chatmanager Chatmanager = chatmanager.getinstancefor (connection);
Newchat = Chatmanager.createchat ("[Email protected]", NULL);

New Thread () {

public void Run () {

while (true) {

try {
Thread.Sleep (3000);
} catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}

Chatmanager.addchatlistener (New Chatmanagerlistener () {

@Override
public void chatcreated (chat chat, Boolean createdlocally) {
if (!createdlocally) {
Chat.addmessagelistener (New Chatmessagelistener () {
@Override
public void ProcessMessage (chat chat, message message) {

if (message.getbody () = = NULL | | message.getbody (). Equals (null)) {

}
else{
System.out
//. println ("Run ...");
System.out
. println ("from" + message.getfrom () + "" + message.getbody ());
Content = content + "\ n" + message.getfrom () + ":" + message.getbody ();
Consts.content = consts.content + "\ n" + message.getfrom () + ":" + message.getbody ();
}


}
});
}
}
});

}

};

}.start ();

} catch (Smackexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (Xmppexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

Public Chat Getchat () {
return newchat;
}

Public String getcontent () {
return content;
}

Public Abstractxmppconnection Getconn () {
return connection;
}

public void Disconn () {
Connection.disconnect ();
}

public static Smacktools getinstance () {
if (Smacktools = = null) {
try {
Smacktools = new Smacktools ();
} catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
return smacktools;
}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Smack 4.1.2+openfire 3.10.2i

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.