首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

对于Smack的研究

2012-12-27 
对于Smack的研究!【原创】今天就先谈谈Smack的连接吧之后,会不断更新!首先来谈谈连接和断开// Create the co

对于Smack的研究!【原创】

今天就先谈谈Smack的连接吧

之后,会不断更新!

首先来谈谈连接和断开

// Create the configuration for this new connectionConnectionConfiguration config = new ConnectionConfiguration("jabber.org", 5222);

config.setCompressionEnabled(true);

config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

// Connect to the serverconnection.connect();

// Log into the serverconnection.login("username", "password", "SomeResource");

....

// Disconnect from the serverconnection.disconnect();

通常情况,会有一些连接会被非可抗力而断开,我们可以用ConnectionConfiguration#setReconnectionAllowed(boolean) 去设置,之后若发生连接断开的问题,则会自动重新reconnection,这样就可以实现非手动连接,如果想手动连接可以用XMPPConnection#connect()进行连接,此时reconnection会自动停止,如果手动连接依然失败,reconnection会自动继续连接。

热点排行