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不是域名是openfireserver的名称

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

}

}

最新文章

  1. ASP.NET MVC 身份认证
  2. Node聊天程序实例06:server.js
  3. Free git private repo
  4. C# Lock 解读[转]
  5. 【软件架构】IM架构设计(安卓版)
  6. 第二个Sprint冲刺第九天
  7. linux cross toolsChain 交叉编译 ARM(转)
  8. Hacker(24)----防范密码被轻易破解
  9. python打印表格式数据,留出正确的空格和段落星号或注释
  10. Swagger入门教程
  11. Appium + Python 测试 QQ 音乐 APP的一段简单脚本
  12. [javascript]multipart/form-data上传格式表单自定义创建
  13. 在Vue中如何使用axios跨域访问数据(转)
  14. 清明 DAY 1
  15. MySQL压力测试(1)-mysqlslap
  16. bzoj5016
  17. JVM Tools
  18. [leetcode]Pow(x, n) @ Python
  19. Selenium (3) —— Selenium IDE + Firefox录制登录脚本(101 Tutorial)
  20. 详解webpack + vue + node 打造单页面(入门篇)

热门文章

  1. c3p0、dbcp、proxool、BoneCP比较
  2. 角点检测:Harris角点及Shi-Tomasi角点检测
  3. BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 总结
  4. ELK kibana查询与过滤
  5. MySQL对索引的使用
  6. xp局域网共享设置
  7. EF操作增删改查
  8. Command 命令模式 MD
  9. 【SDN】SDN相关资料--了解一下电信领域的SDN
  10. ToolBarTray