本文整理汇总了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.");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}