smack debug模式讲解
smakc 内置两套debuging 控制台,让你追踪XMPP服务端和客户端之间所有XML 流动,在smack-debug.jar包含Lite调试器和增强调试器,在smack-core.jar包含debug输出控制台。
调试模式可以用不同的方式来启用:
1、在创建新连接之前,先添加以下代码行:
SmackConfiguration.DEBUG = true;
1、 设置Java系统属性smack.debugenabled真实。可以在命令行上设置系统属性,例如:
java -Dsmack.debugEnabled=true SomeApp
如果你希望在你的应用程序中显式禁用调试模式,可以通过使用命令行参数 或者是在在打开新连接之前,请在应用程序中添加以下行:
SmackConfiguration.DEBUG = false;
smack 使用以下逻辑决定调试控制台使用;
1、它首先会尝试使用在Java系统属性指定类smack.debuggerclass调试器。如果你需要开发属于自己的Debug,需要smackdebugger接口,然后设置系统属性的命令行如:
java -Dsmack.debuggerClass=my.company.com.MyDebugger SomeApp
2、如果第一步失败,Smack会尝试使用增强型Debug,
smackx-debug.jar文件中包含了增强型Debug,因此,你需要将jar文件的路径添加到ClassPath路径中。smack-core.jar Lite调试器和增强调试器不可用的情况下,只有控制台调试器。
增强调试器
当smack Debug模式是启动时,Debug窗口会显示每一个创建连接信息,同时也包含以下信息:
- XMPPConnection tabs -- 每个选项卡显示有关连接的调试信息.
- Smack info tab -- shows information about Smack (e.g. Smack version, installed components, etc.). The connection tab will contain the following information:
- All Stanzas --通过smack 分析发送和接收的数据包的信息分析.
- Raw Sent Stanzas -- 通过Smack产生的原始XML流量发送到服务器.
- Raw Received Stanzas -- 服务器向客户端发送的原始XML.
- Ad-hoc message -- 允许发送特定类型的数据包.
- Information -- 显示连接状态和统计数.
Lite Debugger
当smack Debug模式是启动时,Debug窗口会显示每一个创建连接信息,同时也包含以下信息:
- Client Traffic (red text) -- 通过Smack产生的原始XML流量发送到服务器.
- Server Traffic (blue text) --服务器向客户端发送的原始XML.
- Interpreted Stanzas (green text) -- shows XML packets from the server as parsed by Smack. Right click on any of the panes to bring up a menu with the choices to copy of the contents to the system clipboard or to clear the contents of the pane.