Smack 4.1.2+openfire 3.10.2i

Source: Internet
Author: User

OpenFire and the previous version number configuration does not have much difference is not specifically introduced, the web search will have a lot of illustrations

The following is mainly about the development and use of smack 4.1.2, Read a lot of articles on the Internet contains StackOverflow no more than 4.1 of the use of instructions, at the same time I found some official notes and this version number is incorrect. such as use connectionconfiguration#setreconnectionallowed (Boolean) to turn on/off this feature.   I did not find this method at all. So I wrote some notes for everyone to participate in the same time together to discuss the promotion of the use of smack the latest version.

Here is a link to my participation
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 methods of resolution
I have solved this problem, the Service Name should is the same as OpenFire settings:



The following are the tools I write, chat is the main two things. One is to send a message. One is to receive information, send is smacktools.getchat ();. SendMessage ("detail") gets the content is Chatmanager.addchatlistener (new Chatmanagerlistener () that part, the overall is easier to say, Here are some points to note
(1) The following is the code after Securtymode closed
(2) servername is not a name for Openfireserver
(3) host can change in 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 speech content on the one hand to obtain content and guarantee always online. Like I said on the Internet, the method of re-connecting does not exist in this version number.


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;
}
}

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.