读书人

对于Smack的研究

发布时间: 2012-12-27 10:17:10 作者: rapoo

对于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会自动继续连接。

读书人网 >编程

热点推荐