本文整理匯總了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;
}