smack操作openfire的API介绍(1)

1.连接openfire服务器

  /**
     * 建立即时通讯连接
     * @return
     */
   
  
    public boolean xMPPConnect() {
        boolean result = false;
        ConnectionConfiguration config = new ConnectionConfiguration(serverIp);

        //serverIp表示的是你openfire服务器地址
        config.setReconnectionAllowed(false);

        con = new XMPPConnection(config);

        try {
         //通过xmpp的链接跟OPENFIRE服务器链接,并且通过login的方法,将用户名和密码传递到服务器中,前提是服务器中必须先有关该登陆人员的ID和密码

            con.connect();
           
            con.login(“xxxx”, "xxxxx", "cti", true);
            logger.info(con.getUser() + " 登录即时通讯服务器成功!");
            //系统登陆了以后,XMPPConnection将用户的ID以"ID@jobcn-da5f2ccee/cti"这种方式保存,所有在取得当前用户的时候,要拆分字符串,ID表示的是你登录的账号,@后面的字符串表示的是你在openfire所这是的域名
            result = true;
        } catch (XMPPException ex) {
            logger.warning(person.getId() + " 登录即时通讯服务器失败!");
            result = false;
        }
        return result;
    }

2.初始化客户端信息

   /**
     * 初始化即时通讯
     */
    public void initXMPP() {
        roster = con.getRoster();
        roster.addRosterListener(this);
        PacketFilter filter = new PacketTypeFilter(Message.class);
        con.addPacketListener(this, filter);
        con.addConnectionListener(this);
        //默认开放的两个组"我的好友","最近联系人",这是openfire指定的,名字固定的就是"我的好友","最近联系人"
        RosterGroup rosterGroup_friends = roster.getGroup("我的好友");
        if (rosterGroup_friends == null) {
            rosterGroup_friends = roster.createGroup("我的好友");
        }
        RosterGroup rosterGroup_currentContract = roster.getGroup("最近联系人");
        if (rosterGroup_currentContract == null) {
            rosterGroup_currentContract = roster.createGroup("最近联系人");
        }
      
       
       
        FileTransferManager fileTransferManager = new FileTransferManager(con);
        fileTransferManager.addFileTransferListener(this);
    }

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值