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;

}

}

smack 4.1.2+openfire 3.10.2i的更多相关文章

  1. xmpp openfire smack 介绍和openfire安装及使用

    前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使用 ...

  2. 基于xmpp openfire smack开发之openfire介绍和部署[1]

    前言 http://blog.csdn.net/shimiso/article/details/8816558 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也 ...

  3. Openfire XMPP Smack RTC IM 即时通讯 聊天 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  4. 基于openfire+smack即时通讯instant message开发

    前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire 是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使 ...

  5. (转)基于即时通信和LBS技术的位置感知服务(三):搭建Openfire服务器+测试2款IM客户端

    主要包含4个章节: 1. Java 领域的即时通信的解决方案 2. 搭建 Openfire 服务器 3. 使用客户端测试我们搭建的 Openfire 服务器 4. Smack 和 ASmack 一.J ...

  6. [即时通讯]openfire启动失败解决办法

    当你发现你的电脑上的openfire无论你是重新安装还是重启都无法启动的情况下你可以按照我下面写的那些终端指令来启动你的openfire不用再去重新做你的系统了. 一般你发现你的openfire打开出 ...

  7. openfire安装配置完全教程

    Java领域的IM解决方案 Java领域的即时通信的解决方案可以考虑openfire+spark+smack. Openfire是基于Jabber协议(XMPP)实现的即时通信服务器端,最新版本是3. ...

  8. Apache MiNa 实现多人聊天室

    Apache MiNa 实现多人聊天室 开发环境: System:Windows JavaSDK:1.6 IDE:eclipse.MyEclipse 6.6 开发依赖库: Jdk1.4+.mina-c ...

  9. MAC下的XMPP环境搭建

    实现即时通信有多种方式,下面讲的是Mac下使用XMPP来实现. XML Messages Presence Protocol 可扩展消息处理协议 简单讲就是基于XML语言的点对点即时通信协议  原理: ...

随机推荐

  1. wpf z

    Finding an ancestor of a WPF dependency object This is a simple snippet which helps you to find a sp ...

  2. [翻译] EnterTheMatrix

    Enter The Matrix https://github.com/mpospese/EnterTheMatrix The sample application to accompany my c ...

  3. CRFPP/CRF++编译安装与部署

    CRFPP/CRF++编译安装与部署 下载CRF++ https://taku910.github.io/crfpp/#download 说明:在上面网站中下载CRF++ 0.58 解压 tar zx ...

  4. 在 Sublime Text 2 下开启 Vim 模式

    緣由 由於在 Sublime Text 2 下操作時會想起 Vim 下的鍵盤操作.一時興起在網絡上找了下,發現 Sublime Text 2 是支持類似 Vim 的鍵盤操作的.在此分享下配置過程. 打 ...

  5. MapReduce模式MapReduce patterns

    After having modified and run a job in the last post, we can now examine which are the most frequent ...

  6. 从原型模式(Prototype Pattern)到 Clone

    前面提到抽象工厂的实现,这里说说抽象工厂的原型实现,与工厂方法的实现不同,原型实现有他自己的优点和缺点 原型的优点: 1. 效率:clone是native方法,比new的效率高,当使用复杂循环嵌套对象 ...

  7. 使用Adt自带的工具进行Android自己主动化測试(三)

    在这个系列的上一篇文章中,我们介绍了MonkeyRunner,并提到假设依据坐标来编写自己主动化脚本的话存在着一定的局限性(点击文末"阅读原文"能够打开这篇文章查看).这篇文章将进 ...

  8. OpenCV学习(17) 细化算法(5)

    本章我们看下Pavlidis细化算法,参考资料http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/con ...

  9. 混沌数学之Duffing(杜芬)振子

    杜芬振子 Duffing oscillator是一个描写强迫振动的振动子,由非线性微分方程表示 杜芬方程列式如下: 其中 γ控制阻尼度 α控制韧度 β控制动力的非线性度 δ驱动力的振幅 ω驱动力的圆频 ...

  10. Windows下安装和配置Apache2.2.22服务器+PHP5+Mysql5

    接下来,笔者将WindowsXP(Sp3)下,搭建和配置php运行环境做一个简单的介绍: 1.安装准备 1.1Apache下载,官方地址(http://httpd.apache.org/),此处笔者下 ...