当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionConfiguration.setReconnectionAllowed方法代码示例

本文整理汇总了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;
}
 
开发者ID:FanHuaRan,项目名称:SmackStudy,代码行数:35,代码来源:XMPPUtil.java

示例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;
}
 
开发者ID:lfkdsk,项目名称:PracticeCode,代码行数:31,代码来源:XSCHelper.java

示例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;
}
 
开发者ID:cowthan,项目名称:AyoSunny,代码行数:20,代码来源:XmppConnectionManager.java

示例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;
}
 
开发者ID:jingshauizh,项目名称:androidsummary,代码行数:26,代码来源:XmppConnectionManager.java

示例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;
	}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:29,代码来源:XmppConnectionManager.java

示例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());
}
 
开发者ID:gongmingqm10,项目名称:SmackDemo,代码行数:8,代码来源:XMPPManager.java

示例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);
	}
}
 
开发者ID:jackhatedance,项目名称:visual-programming,代码行数:30,代码来源:XmppAgent.java

示例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();
            }
        }
 
开发者ID:phoenixNirvana,项目名称:NewCommunication-Android,代码行数:49,代码来源:XmppManager.java


注:本文中的org.jivesoftware.smack.ConnectionConfiguration.setReconnectionAllowed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。