smack 4.1.2+openfire 3.10.2i
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了smack 4.1.2+openfire 3.10.2i,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3582字,纯文字阅读大概需要6分钟。
内容图文
openfire 和以往版本配置没有多大区别就不详细介绍了,网上搜会有一大堆的图解下面主要说一下smack 4.1.2 的开发使用,在网上看了好多文章包括stackoverflow的都没有4.1以上的使用说明,同时我发现官方的一些说明好像和这个版本不对应,例如UseConnectionConfiguration#setReconnectionAllowed(boolean) to turn on/off this feature, 我查了根本没有这个方法,所以以就自己写了一些笔记,供大家参考,同时共同讨论促进大家使用smack的最新版。
以下是我参考的链接
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问题
https://issues.jenkins-ci.org/browse/JENKINS-25505
认证方式
http://blog.csdn.net/coding_me/article/details/39524137
0认证的解决办法
I have solved this problem, the Service Name should be the same as openfire settings:
下面是我写的工具类,聊天也就主要两件事情,一个就是发送信息,一个是接受信息,发送就是smackTools.getChat();.sendMessage("detail") 获取内容就是 chatManager.addChatListener(new ChatManagerListener()
那一部分,总体讲比较简单,以下说明需要注意的几点
(1)以下是securtyMode关闭之后的代码
(2)ServerName不是域名是openfire服务器的名称
(3)host可以在host文件中更改
(4)connect.login()完必须循环有操作否则会在别人那里显示为脱机状态
(5) newChat = chatManager.createChat("why2@why-pc",null); @后面是serverName
(6)使用完必须关闭连接否则会出现发送一条多条显示的现象。因为每个对话都是单独一条线程
(7)采用循环让获取对方说话内容一方面获取内容了而且保证一直在线,像网上说的那个设置重连的方法在这版本中不存在
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();
//获取的谈话
//chat
final ChatManager chatManager = ChatManager.getInstanceFor(connection);
newChat = chatManager.createChat("why2@why-pc",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;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/whybangbang/article/details/46898785
内容总结
以上是互联网集市为您收集整理的smack 4.1.2+openfire 3.10.2i全部内容,希望文章能够帮你解决smack 4.1.2+openfire 3.10.2i所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。