Openfire 即时通讯系统(服务器端+Android客户端)一

    xiaoxiao2022-07-05  210

    目标: 搭建一个小型的即时通讯系统。

    服务器端: Openfire

    Android客户端:Smack

    开发环境:Windows10、JDK、Android SDK

    IDE: Android Studio

    数据库: MySQL(Windows下推荐使用wnmp)

    开始!

     

    一、 服务器端

     

    1.  直接从openfire的github仓库下载release版本:https://github.com/igniterealtime/Openfire/releases/download/v4.3.2/openfire_4_3_2.zip

    版本是最新的4.3.2(2019/05/22)

     

    2. 配置java环境(后面要开发android,这个应该都有了)

     

    3. 安装数据库,并准备一个空的数据库。

     

    4. 解压openfire到一个目录。

     

    5. 打开命令行,进入openfire/bin目录,执行:

    openfire.bat

    6. 这时会弹出一个java的命令行界面,显示如下:

     

    8.  打开浏览器,访问:http://localhost:9090

     

    选择简体中文,点击continue。

     

    9.  填写域和Host地址,这里因为是本地搭建,写任意的就行比如:test.com

     

    10. 接着选择“标准数据库连接”

    11. 配置数据库,填写数据库的地址、名称和用户名密码

     

    11.1 注意,这时如果使用默认的编码设置,可能会收到这样一条错误:

    11.2 提示我们看error.log,打开openfire/logs/error.log文件,我们发现了这个报错:

    这个是时区设置问题,解决办法:在设置数据库连接地址的地方加上时区和编码格式的设置:

    useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

    就行了。

    但是

    在设置完这个结果后,如果重启openfire,可能会遇到这种错误:

    java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 retries. The exception from the last attempt is as follows: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC'.

    打开openfire生成的目录里的openfire配置文件:

    E:\server\openfire1\Openfire\distribution\target\distribution-base\conf\openfire.xml

    找到这行:

    <serverURL>jdbc:mysql://localhost:3306/openfire?rewriteBatchedStatements=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC</serverURL>

    会发现里面的“&”符合被转义成了“&amp;”但是每个转义都多了一个“amp;”,改成这个“&”就行了。

     

    12. 接着选择默认设置

    13. 设置管理员密码

    14. 完成设置。

     

    15. 登录页面,openfire启动成功。

     

    下一篇文章开始开发Android客户端程序。

    最新回复(0)