本文整理匯總了Java中org.jivesoftware.smack.ConnectionConfiguration.setReconnectionAllowed方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionConfiguration.setReconnectionAllowed方法的具體用法?Java ConnectionConfiguration.setReconnectionAllowed怎麽用?Java ConnectionConfiguration.setReconnectionAllowed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.ConnectionConfiguration
的用法示例。
在下文中一共展示了ConnectionConfiguration.setReconnectionAllowed方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createXMPPConnection
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
/**
* 工廠模式獲取連接對象 還沒有連接服務器
* @param connectionTimeOut 連接超時的時間
* @param reconnectionAllowed 是否準許重連接
* @param isPresence 是否在線
* @param debugEnable 是否調試
* @param securityMode 安全模式
* @param connectionListener 連接監聽器
* @return
*/
public static XMPPConnection createXMPPConnection(int connectionTimeOut, boolean reconnectionAllowed, boolean isPresence, boolean debugEnable,
ConnectionConfiguration.SecurityMode securityMode, ConnectionListener connectionListener) {
//設置是否開啟DEBUG模式
XMPPConnection.DEBUG_ENABLED = debugEnable;
//設置連接地址、端口
ConnectionConfiguration configuration = new ConnectionConfiguration(SERVERADDRESS, PORT);
//設置服務器名稱
configuration.setServiceName(SERVERNAME);
//設置是否需要SAS驗證
configuration.setSASLAuthenticationEnabled(false);
//設置安全類型
configuration.setSecurityMode(securityMode);
//設置用戶狀態
configuration.setSendPresence(isPresence);
//設置是否準許重連接
configuration.setReconnectionAllowed(reconnectionAllowed);
//實例化連接對象
XMPPConnection xmppConnection = new XMPPConnection(configuration);
//添加連接監聽器
if (connectionListener != null) {
xmppConnection.addConnectionListener(connectionListener);
}
return xmppConnection;
}
示例2: connectToServer
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
/**
* 建立與服務器的持久連接 (必須僅能被getConnection()直接調用)
*
* @return boolean 成功。如成功連接服務器返回true,否則false
*/
private boolean connectToServer() {
if (connection == null || !connection.isConnected()) {
try {
//配置連接
XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config =
new ConnectionConfiguration(HOST, PORT, GROUP);
config.setReconnectionAllowed(true);
config.setSendPresence(false);
//創建並連接
connection = new XMPPConnection(config);
connection.connect();
if(!connection.isConnected())
throw new XMPPException();
return connection.isConnected();
} catch (XMPPException e) {
e.printStackTrace();
connection = null;
}
}
return false;
}
示例3: init
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
public XMPPConnection init() {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
ConnectionConfiguration connectionConfig = new ConnectionConfiguration(Const.XMPP_HOST, Const.XMPP_PORT);
// connectionConfig.setSASLAuthenticationEnabled(false);//
// 不使用SASL驗證,設置為false
// connectionConfig
// .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// 允許自動連接
connectionConfig.setReconnectionAllowed(true);
// 允許登陸成功後更新在線狀態
connectionConfig.setSendPresence(true);
// 收到好友邀請後manual表示需要經過同意,accept_all表示不經同意自動為好友
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
XMPPConnection connection = new XMPPConnection(connectionConfig);
return connection;
}
示例4: init
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
/**
* 初始化連接
* @param loginConfig
* @return
*/
public XMPPConnection init(IMConfig loginConfig) {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
connectionConfig = new ConnectionConfiguration(
loginConfig.getXmppHost(), loginConfig.getXmppPort(),
loginConfig.getXmppServiceName());
//connectionConfig.setSASLAuthenticationEnabled(false);// 不使用SASL驗證,設置為false
connectionConfig
.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// 允許自動連接
connectionConfig.setReconnectionAllowed(false);
// 允許登陸成功後更新在線狀態
connectionConfig.setSendPresence(true);
// 收到好友邀請後manual表示需要經過同意,accept_all表示不經同意自動為好友
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
connection = new XMPPConnection(connectionConfig);
return connection;
}
示例5: init
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
public XMPPConnection init(LoginConfig loginConfig) {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
connectionConfig = new ConnectionConfiguration(
loginConfig.getXmppHost(), loginConfig.getXmppPort(),
loginConfig.getXmppServiceName());
try {
Class.forName("org.jivesoftware.smackx.ServiceDiscoveryManager", true, XmppConnectionManager.class.getClassLoader());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/// ServiceDiscoveryManager discoManager = new ServiceDiscoveryManager(connection);
connectionConfig.setSASLAuthenticationEnabled(false);// ��ʹ��SASL��֤������Ϊfalse
connectionConfig
.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// �����Զ�����
connectionConfig.setReconnectionAllowed(false);
// �����½�ɹ����������״̬
connectionConfig.setSendPresence(true);
// connectionConfig.setSendPresence(false);
// �յ����������manual��ʾ��Ҫ����ͬ��,accept_all��ʾ����ͬ���Զ�Ϊ����
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
connection = new XMPPConnection(connectionConfig);
return connection;
}
示例6: XMPPManager
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
private XMPPManager() {
config = new ConnectionConfiguration(serverAddress, 5222, serverName);
config.setReconnectionAllowed(true);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connection = new XMPPTCPConnection(config);
connection.addConnectionListener(new XMPPConnectionListener());
}
示例7: connect
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
public void connect() {
try {
ConnectionConfiguration config = new ConnectionConfiguration(server, 5222);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
config.setReconnectionAllowed(true);
connection = new XMPPConnection(config);
connection.connect();
connection.login(username, password);
final ChatManager chatManager = connection.getChatManager();
chatManager.addChatListener(new ChatManagerListener() {
@Override
public void chatCreated(Chat chat, boolean createdLocally) {
chat.addMessageListener(getMessageListener());
}
});
} catch (XMPPException e) {
throw new RuntimeException(e);
}
}
示例8: run
import org.jivesoftware.smack.ConnectionConfiguration; //導入方法依賴的package包/類
public void run() {
Log.i(LOGTAG, "ConnectTask.run()...");
if (!xmppManager.isConnected()) {
// Create the configuration for this new connection
ConnectionConfiguration connConfig = new ConnectionConfiguration(
"10.58.108.201", 5222);
// connConfig.setSecurityMode(SecurityMode.disabled);
connConfig.setSecurityMode(SecurityMode.required);
connConfig.setSASLAuthenticationEnabled(false);
connConfig.setCompressionEnabled(false);
connConfig.setDebuggerEnabled(true);
connConfig.setReconnectionAllowed(true);
connConfig.setSendPresence(true);
XMPPConnection connection = new XMPPConnection(connConfig);
xmppManager.setConnection(connection);
try {
// Connect to the server
connection.connect();
Log.i(LOGTAG, "XMPP connected successfully");
// // packet provider
ProviderManager.getInstance().addIQProvider("notification",
"androidpn:iq:notification",
new NotificationIQProvider());
if(mConnectListener != null){
mConnectListener.connectSuccess();
}
} catch (XMPPException e) {
Log.e(LOGTAG, "XMPP connection failed", e);
if(mConnectListener != null){
mConnectListener.connectFail();
}
}
xmppManager.runTask();
} else {
Log.i(LOGTAG, "XMPP connected already");
xmppManager.runTask();
}
}