本文整理匯總了Java中org.jivesoftware.smack.tcp.XMPPTCPConnection.addConnectionListener方法的典型用法代碼示例。如果您正苦於以下問題:Java XMPPTCPConnection.addConnectionListener方法的具體用法?Java XMPPTCPConnection.addConnectionListener怎麽用?Java XMPPTCPConnection.addConnectionListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.tcp.XMPPTCPConnection
的用法示例。
在下文中一共展示了XMPPTCPConnection.addConnectionListener方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: XMPPConnector
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的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: initGroupConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的package包/類
private void initGroupConnection() {
long currentUserId = CurrentUser.getInstance().getCurrentUserId();
String currentUserPassword = CurrentUser.getInstance().getCurrentPassword();
String jid = currentUserId + "-" + ApiConstants.APP_ID;
groupChatConnection = new XMPPTCPConnection(
jid, currentUserPassword, ApiConstants.MULTI_USERS_CHAT_ENDPOINT);
groupChatConnection.addConnectionListener(this);
}
示例3: initPrivateConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的package包/類
private void initPrivateConnection() {
long currentUserId = CurrentUser.getInstance().getCurrentUserId();
String currentUserPassword = CurrentUser.getInstance().getCurrentPassword();
String userName = currentUserId + "-" + ApiConstants.APP_ID;
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(userName, currentUserPassword);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setServiceName(ApiConstants.CHAT_END_POINT);
configBuilder.setHost(ApiConstants.CHAT_END_POINT);
configBuilder.setDebuggerEnabled(true);
privateChatConnection = new XMPPTCPConnection(configBuilder.build());
privateChatConnection.addConnectionListener(this);
ReconnectionManager manager = ReconnectionManager.getInstanceFor(privateChatConnection);
manager.enableAutomaticReconnection();
manager.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
manager.setFixedDelay(15);
ProviderManager.addExtensionProvider(Displayed.ELEMENT, Displayed.NAMESPACE, new Displayed.Provider());
DisplayedManager.getInstanceFor(privateChatConnection).addDisplayedListener(
(fromJid, toJid, receiptId, receipt) -> {
messageService.get().processDisplayed(fromJid, toJid, receiptId, receipt);
});
ProviderManager.addExtensionProvider(Received.ELEMENT, Received.NAMESPACE, new Received.Provider());
ReceivedManager.getInstanceFor(privateChatConnection).addReceivedListener(
(fromJid, toJid, receiptId, receipt) -> {
messageService.get().processReceived(fromJid, toJid, receiptId, receipt);
});
}
示例4: createConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的package包/類
private void createConnection() {
Logger.debug(TAG, "creating new connection to " + mAccount.getHost() + ":" + mAccount.getPort());
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()
.setServiceName(mAccount.getServiceName())
.setResource(mAccount.getResourceName())
.setHost(mAccount.getHost())
.setPort(mAccount.getPort())
.setUsernameAndPassword(mAccount.getXmppJid(), mAccount.getPassword())
.setConnectTimeout(XmppService.CONNECT_TIMEOUT);
if (XmppService.CUSTOM_SSL_CONTEXT != null) {
Logger.debug(TAG, "setting custom SSL context");
builder.setCustomSSLContext(XmppService.CUSTOM_SSL_CONTEXT);
}
if (XmppService.CUSTOM_HOSTNAME_VERIFIER != null) {
Logger.debug(TAG, "setting custom hostname verifier");
builder.setHostnameVerifier(XmppService.CUSTOM_HOSTNAME_VERIFIER);
}
mConnection = new XMPPTCPConnection(builder.build());
mConnection.setUseStreamManagement(XmppService.USE_STREAM_MANAGEMENT);
mConnection.setUseStreamManagementResumption(XmppService.USE_STREAM_MANAGEMENT);
mConnection.setPreferredResumptionTime(XmppService.STREAM_MANAGEMENT_RESUMPTION_TIME);
mConnection.addConnectionListener(this);
}
示例5: XMPPManager
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的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());
}
示例6: connect
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入方法依賴的package包/類
public void connect() throws IOException, XMPPException, SmackException {
Log.i(TAG, "connect()");
XMPPTCPConnectionConfiguration.XMPPTCPConnectionConfigurationBuilder builder = XMPPTCPConnectionConfiguration.builder();
builder.setServiceName(mServiceName);
builder.setResource("SmackAndroidTestClient");
builder.setUsernameAndPassword(mUsername, mPassword);
builder.setRosterLoadedAtLogin(true);
mConnection = new XMPPTCPConnection(builder.build());
//Set ConnectionListener here to catch initial connect();
mConnection.addConnectionListener(this);
mConnection.connect();
mConnection.login();
PingManager.setDefaultPingInterval(600); //Ping every 10 minutes
PingManager pingManager = PingManager.getInstanceFor(mConnection);
pingManager.registerPingFailedListener(this);
setupSendMessageReceiver();
ChatManager.getInstanceFor(mConnection).addChatListener(this);
mConnection.getRoster().addRosterListener(this);
}