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


Java ConnectionConfiguration类代码示例

本文整理汇总了Java中org.jivesoftware.smack.ConnectionConfiguration的典型用法代码示例。如果您正苦于以下问题:Java ConnectionConfiguration类的具体用法?Java ConnectionConfiguration怎么用?Java ConnectionConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionConfiguration类属于org.jivesoftware.smack包,在下文中一共展示了ConnectionConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: XMPPConnector

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
/**
 * The constructor for the XMPP bot.
 *
 * @param host
 *            The server the bot should login.
 * @param port
 *            The hosts port.
 * @param login
 *            The bots login name.
 * @param password
 *            The bots login password.
 * @param resource
 *            The bots resource (i.e. Work or Home). Can be null.
 * @throws IllegalArgumentException
 *             Throws an {@link IllegalArgumentException} if some of the parameters are in an
 *             invalid format.
 */
public XMPPConnector(String host, String port, String login, String password, String resource)
        throws IllegalArgumentException {
    checkParameters(host, port, login, password, resource);
    int numericalPort = port == null ? DEFAULT_XMPP_PORT : Integer.parseInt(port);
    this.sender = login + "@" + host + "/" + resource;
    SmackConfiguration.DEBUG_ENABLED = Boolean.parseBoolean(ApplicationPropertyXmpp.DEBUG
            .getValue());
    ProviderManager.addExtensionProvider(AliasPacketExtension.ALIAS_ELEMENT_NAME,
            AliasPacketExtension.ALIAS_NAMESPACE, AliasPacketExtension.class);
    ConnectionConfiguration config = new ConnectionConfiguration(host, numericalPort);
    connection = new XMPPTCPConnection(config);
    connect(login, password, resource);
    sendPriorityPresence();
    if (connection.isConnected()) {
        LOG.info(ResourceBundleManager.instance().getText("xmpp.connection.started",
                Locale.ENGLISH));
        connection.addConnectionListener(new XMPPConnectionStatusLogger());
    } else {
        LOG.info("The XMPP connection wasn't established.");
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:39,代码来源:XMPPConnector.java

示例2: 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

示例3: getConnectionConfigBuilder

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
public XMPPTCPConnectionConfiguration.Builder getConnectionConfigBuilder() {
	if (!isBasicConfigurationDone()) return null;

	if (confBuilderCache == null) {
		XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();

		String password = getPassword();
		builder.setUsernameAndPassword(getMyJid().getLocalpart(), password);
		builder.setXmppDomain(getMyJid().asDomainBareJid());

		builder.setSecurityMode(ConnectionConfiguration.SecurityMode.required);

		SSLContext sc;
		try {
			sc = SSLContext.getInstance("TLS");
			sc.init(null, new X509TrustManager[] { mMemorizingTrustManager }, new java.security.SecureRandom());
		} catch (KeyManagementException | NoSuchAlgorithmException e) {
			throw new IllegalStateException(e);
		}
		builder.setCustomSSLContext(sc);

		confBuilderCache = builder;
	}
	return confBuilderCache;
}
 
开发者ID:Flowdalic,项目名称:android-xmpp-iot-demo,代码行数:26,代码来源:Settings.java

示例4: 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

示例5: XMPPWithIQProtocol

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
public XMPPWithIQProtocol(String ipAddress, int port, String user,
		String password) throws XMPPException {
	
	// Connect:
	config = new ConnectionConfiguration(ipAddress, port);
	config.setSASLAuthenticationEnabled(false);
       config.setSecurityMode(SecurityMode.disabled);
       
       connection = new XMPPConnection(config);
       connection.connect();
       
       // Login:
       connection.login(user, password, "root");
       
       // Add IQ provider:
       ProviderManager.getInstance().addIQProvider("query", "iq:myOwn", new MyIQProvider());
}
 
开发者ID:tokahuke,项目名称:java-for-playwrights,代码行数:18,代码来源:XMPPWithIQProtocol.java

示例6: 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

示例7: connect

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
@Override
public void connect(XmppURI uri, String password) throws IOException, XMPPException, SmackException {
    this.disconnect();

    XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword(uri.getNode(), password)
            .setServiceName(uri.getDomain())
            .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
            .setDebuggerEnabled(true)
            .build();
    AbstractXMPPConnection connection = new XMPPTCPConnection(configuration);
    connection.connect();
    connection.login();
    // keep connection alive
    // when connection is idle it will run into timeout
    PingManager pingManager = PingManager.getInstanceFor(connection);
    pingManager.setPingInterval(60);
    pingManager.pingMyServer();

    this.connection = connection;
}
 
开发者ID:citlab,项目名称:Intercloud,代码行数:22,代码来源:XmppConnectionManager.java

示例8: getXMPPConnection

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
/**
 * Gets the XMPP connection.
 *
 * @return the XMPP connection
 */
public XMPPConnection getXMPPConnection()
{
	if (this.xmpp == null)
	{
		ConnectionConfiguration config = new ConnectionConfiguration(serverConfigPrefsItem.getClusterHost(), serverConfigPrefsItem.getPort());
		config.setSASLAuthenticationEnabled(false);
		config.setDebuggerEnabled(false);
		this.xmpp = new XMPPConnection(config);
		try
		{
			xmpp.connect();
			xmpp.login(identity, serverConfigPrefsItem.getClusterPassword());
		}
		catch (XMPPException e)
		{
			e.printStackTrace();
		}
	}
	return xmpp;
}
 
开发者ID:synergynet,项目名称:synergynet3.1,代码行数:26,代码来源:SynergyNetCluster.java

示例9: setup

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
@PostConstruct
void setup() {
	try {
		if (host.isEmpty() || user.isEmpty() || pass.isEmpty()) {
			log.info("disabling XMPP support; incomplete configuration");
			conn = null;
			return;
		}
		ConnectionConfiguration cfg = new ConnectionConfiguration(host);
		cfg.setSendPresence(false);
		XMPPConnection c = new XMPPConnection(cfg);
		c.connect();
		c.login(user, pass, resource);
		conn = c;
		log.info("connected to XMPP service <" + host + "> as user <"
				+ user + ">");
	} catch (Exception e) {
		log.info("failed to connect to XMPP server", e);
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-server,代码行数:21,代码来源:JabberDispatcher.java

示例10: 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

示例11: connect

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
public static XMPPConnection connect(String host) throws XMPPException
{
    ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(host, 5222, "excalibur.org");
    connectionConfiguration.setCompressionEnabled(false);
    connectionConfiguration.setSelfSignedCertificateEnabled(true);
    connectionConfiguration.setExpiredCertificatesCheckEnabled(false);
    connectionConfiguration.setDebuggerEnabled(false);
    connectionConfiguration.setSASLAuthenticationEnabled(true);
    connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
    //XMPPConnection.DEBUG_ENABLED = false;
    
    XMPPConnection connection = new XMPPConnection(connectionConfiguration);
    connection.connect();
    
    return connection;
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:17,代码来源:Client.java

示例12: build

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
public ConnectionConfiguration build()
{
    Preconditions.checkArgument(!Strings.isNullOrEmpty(this.host_) && !Strings.isNullOrEmpty(this.serviceName_));
    ConnectionConfiguration configuration = new ConnectionConfiguration(host_, port_, serviceName_);

    configuration.setCompressionEnabled(this.compressionEnabled_);
    configuration.setSelfSignedCertificateEnabled(this.selfSignedCertificateEnabled_);
    configuration.setExpiredCertificatesCheckEnabled(this.expiredCertificatesCheckEnabled_);
    configuration.setSASLAuthenticationEnabled(this.saaslAuthenticationEnabled_);
    configuration.setSecurityMode(this.securityMode_);
    configuration.setRosterLoadedAtLogin(this.loadRosterAtLogin_);
    configuration.setSendPresence(this.sendPresence_);

    return configuration;

}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:17,代码来源:XMPPConnectionConfigurationBuilder.java

示例13: LolChat

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
/**
 * Represents a single connection to a League of Legends chatserver.
 * 
 * @param server
 *            The chatserver of the region you want to connect to
 * @param friendRequestPolicy
 *            Determines how new Friend requests are treated.
 * @param riotApiKey
 *            Your apiKey used to convert summonerId's to name. You can get
 *            your key here <a
 *            href="https://developer.riotgames.com/">developer
 *            .riotgames.com</a>
 * 
 * @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
 * @see LolChat#setFriendRequestListener(FriendRequestListener)
 */
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
		RiotApiKey riotApiKey) {
	this.friendRequestPolicy = friendRequestPolicy;
	this.server = server;
	if (riotApiKey != null && server.api != null) {
		this.riotApi = RiotApi.build(riotApiKey, server);
	}
	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
	final ConnectionConfiguration config = new ConnectionConfiguration(
			server.host, 5223, "pvp.net");
	config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
	config.setSocketFactory(SSLSocketFactory.getDefault());
	config.setCompressionEnabled(true);
	connection = new XMPPTCPConnection(config);

	addListeners();
}
 
开发者ID:TheHolyWaffle,项目名称:League-of-Legends-XMPP-Chat-Library,代码行数:34,代码来源:LolChat.java

示例14: ConnectionManager

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
public ConnectionManager(Context context,
		ConnectionStatusCallback statusCallback,
		CommunicationManager communicationManager) {
	this.statusCallback = statusCallback;
	this.communicationManager = communicationManager;

	smack = SmackAndroid.init(context);

	SASLAuthentication.registerSASLMechanism(GTalkOAuthSASLMechanism.NAME,
			GTalkOAuthSASLMechanism.class);
	SASLAuthentication
			.supportSASLMechanism(GTalkOAuthSASLMechanism.NAME, 0);

	ConnectionConfiguration configuration = new ConnectionConfiguration(
			"talk.google.com", 5222, "gmail.com");
	configuration.setSASLAuthenticationEnabled(true);

	connection = new XMPPConnection(configuration);
}
 
开发者ID:nickglobal,项目名称:TvPoo,代码行数:20,代码来源:ConnectionManager.java

示例15: makeXMPPConnection

import org.jivesoftware.smack.ConnectionConfiguration; //导入依赖的package包/类
private Connection makeXMPPConnection(String username, String password){
	// Create the configuration for this new connection
	ConnectionConfiguration config = new ConnectionConfiguration("libraryh3lp.com", 5222);
	config.setCompressionEnabled(true);
	config.setSASLAuthenticationEnabled(true);
	
	// Create the connection and log in
	Connection con = new XMPPConnection(config);
	try {
		con.connect();
		con.login(username, password);
	} catch (XMPPException e) {
		e.printStackTrace();
		con = null;
	}
	
	return con;
}
 
开发者ID:jswelker,项目名称:LibraryH3lp-Transfer-Bot,代码行数:19,代码来源:Chat.java


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