`
houchangxi
  • 浏览: 63312 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

对于Smack的研究!【原创】

阅读更多

今天就先谈谈Smack的连接吧

之后,会不断更新!

首先来谈谈连接和断开

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

config.setCompressionEnabled(true);

config.setSASLAuthenticationEnabled(true);

XMPPConnection connection = new XMPPConnection(config);

// Connect to the server connection.connect();

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

....

// Disconnect from the server connection.disconnect();

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics