本文整理汇总了Java中org.jivesoftware.smack.AbstractXMPPConnection类的典型用法代码示例。如果您正苦于以下问题:Java AbstractXMPPConnection类的具体用法?Java AbstractXMPPConnection怎么用?Java AbstractXMPPConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractXMPPConnection类属于org.jivesoftware.smack包,在下文中一共展示了AbstractXMPPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
protected Boolean doInBackground(String... jid) {
// Get the XMMPConnection from the manager
AbstractXMPPConnection conn = XMPPConnectionManager.getConnection();
// Obtain the PingManager associated with my XMPP connection
this.pingManager = PingManager.getInstanceFor(conn);
// I do not want background pings but a single foreground ping
pingManager.setPingInterval( -1 );
// Do the ping
try {
return pingManager.ping( jid[0] );
} catch (Exception ex) {
Log.w(LOGTAG, "XMPP error " + ex);
this.errorMessage = "XMPP error:" + ex ;
return false ;
}
}
示例2: doInBackground
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
protected EntityViewActivity doInBackground(EntityViewActivity... activity) {
// Get the XMMPConnection from the manager
AbstractXMPPConnection conn = XMPPConnectionManager.getConnection();
// Obtain the ServiceDiscoveryManager associated with my XMPP connection
this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn);
Entity entity = activity[0].myEntity;
try {
if ( entity.getNode() != null && entity.getNode() != "" ) {
activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() );
} else {
activity[0].myLeafInfo = discoManager.discoverInfo( entity.getJid() );
}
Log.d(LOGTAG, "Got Info!");
} catch (Exception ex) {
Log.w(LOGTAG, "XMPP Disco error " + ex);
errorMessage = ex.toString() ;
}
return activity[0];
}
示例3: connect
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的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;
}
示例4: getConnection
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public AbstractXMPPConnection getConnection() throws SmackException.NotConnectedException {
if (null == this.connection) {
logger.warn("Could not get Xmpp Connection, connection was null.");
throw new SmackException.NotConnectedException();
} else if (!this.connection.isConnected()) {
try {
// reconnect if ran into timeout
this.connection.connect();
} catch (Exception e) {
this.connection = null;
logger.error("Could not get Xmpp Connection, failed to reconnect.");
throw new SmackException.NotConnectedException();
}
}
return this.connection;
}
示例5: sendRestDocument
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public ResourceDocument sendRestDocument(XmppURI uri, ResourceDocument document) throws XMPPException, IOException, SmackException {
AbstractXMPPConnection connection = this.connectionManager.getConnection();
// create an set IQ stanza to uri
RestIQ setIQ = new RestIQ(uri, document);
// send stanza
connection.sendStanza(setIQ);
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(setIQ, connection));
PacketCollector collector = connection.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
if(resultIQ instanceof RestIQ) {
// create rest doc
return ((RestIQ) resultIQ).getResourceDocument();
} else {
throw new SmackException("Wrong RestIQ has been passed");
}
}
示例6: getXwadlDocument
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public ResourceTypeDocument getXwadlDocument(XmppURI uri) throws XMPPException, IOException, SmackException {
AbstractXMPPConnection connection = this.connectionManager.getConnection();
// create an get IQ stanza to uri
IQ getIQ = new GetXwadlIQ(uri);
// send stanza
connection.sendStanza(getIQ);
// wait for response
StanzaFilter filter = new AndFilter(new IQReplyFilter(getIQ, connection));
PacketCollector collector = connection.createPacketCollector(filter);
IQ resultIQ = collector.nextResultOrThrow();
if (resultIQ instanceof XwadlIQ) {
// create xwadl
return ((XwadlIQ) resultIQ).getXwadl();
} else {
throw new SmackException("Wrong IQ has been passed");
}
}
示例7: perform
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
if (!sampler.getXMPPConnection().isConnected()) {
return res;
}
AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection();
conn.disconnect();
if (sampler.getXMPPConnectionConfig() != null)
sampler.getXMPPConnectionConfig().resetConnection();
return res;
}
示例8: perform
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection();
conn.connect();
res.setResponseData(sampler.getXMPPConnection().getConnectionID().getBytes());
return res;
}
示例9: perform
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
XMPPConnection conn = sampler.getXMPPConnection();
String loginStr = sampler.getPropertyAsString(LOGIN);
String pwdStr = sampler.getPropertyAsString(PASSWORD);
String resStr = sampler.getPropertyAsString(RESOURCE);
res.setSamplerData("Username: " + loginStr + "\nPassword: " + pwdStr + "\nResource: " + resStr);
AbstractXMPPConnection absConn = (AbstractXMPPConnection) conn;
if (loginStr.isEmpty()) {
absConn.loginAnonymously();
} else {
absConn.login(loginStr, pwdStr, resStr);
}
return res;
}
示例10: doInBackground
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
@Override
protected Boolean doInBackground(ArrayList<Entity>... entityList) {
Entity entity = null ;
Iterator entityIterator = entityList[0].iterator();
// Get the XMMPConnection from the manager
AbstractXMPPConnection conn = XMPPConnectionManager.getConnection();
// Obtain the ServiceDiscoveryManager associated with my XMPP connection
this.discoManager = ServiceDiscoveryManager.getInstanceFor(conn);
while ( entityIterator.hasNext() ) {
if (this.isCancelled()) {
Log.d(LOGTAG , "Cancelling" );
return null;
}
Log.d(LOGTAG , "Loading info for icons" );
entity = (Entity) entityIterator.next();
try {
if ( entity.getNode() != null && entity.getNode() != "" ) {
entityInfo = discoManager.discoverInfo( entity.getJid() , entity.getNode() );
} else {
entityInfo = discoManager.discoverInfo( entity.getJid() );
}
} catch (Exception ex) {
Log.w(LOGTAG, "XMPP Disco error " + ex);
errorMessage = ex.toString() ;
this.publishProgress( false );
continue;
}
entity.setIdentities( entityInfo.getIdentities() );
this.publishProgress( true );
}
return null ;
}
示例11: getConnection
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
public static AbstractXMPPConnection getConnection() {
if ( XMPPConnectionManager.isConfigured == false ) {
Log.w(LOGTAG, "Instating unconfigured connection" );
return null;
}
if ( XMPPConnectionManager.isConnected == false ) {
// Send the configuration
// TODO: Yes I know, this is restrictive, DNS must be working
XMPPTCPConnectionConfiguration.Builder configBuilder =
XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(
XMPPConnectionManager.xmppUserName,
XMPPConnectionManager.xmppPassword);
configBuilder.setServiceName( XMPPConnectionManager.xmppUserDomain );
configBuilder.setResource( "FlowsManager" );
XMPPConnectionManager.connection = new XMPPTCPConnection(configBuilder.build());
try {
// Create a connection to the XMPP server.
XMPPConnectionManager.connection.connect();
// Log into the server
XMPPConnectionManager.connection.login();
} catch (Exception ex) {
Log.w(LOGTAG, "XMPP Connection error " + ex);
return null ;
}
XMPPConnectionManager.isConnected = true ;
}
return XMPPConnectionManager.connection ;
}
示例12: TestClient
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
public TestClient(AbstractXMPPConnection connection) throws XMPPErrorException, URISyntaxException, SmackException, XmlException {
this.connection = connection;
discover();
}
示例13: getConnection
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
public AbstractXMPPConnection getConnection() {
return mConn;
}
示例14: registerAccount
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
public void registerAccount(View view) {
final EntityBareJid jid = mSettings.getJid();
final String password = mSettings.getPassword();
if (jid == null) {
Toast.makeText(this, "Please enter a valid bare JID", Toast.LENGTH_SHORT).show();
return;
}
if (password.isEmpty()) {
Toast.makeText(this, "Please enter a password", Toast.LENGTH_SHORT).show();
return;
}
(new Thread() {
@Override
public void run() {
if (!ConnectivityManagerUtil.hasDataConnection(InfoAndSettings.this)) {
showToast("Data connection not available", Toast.LENGTH_SHORT);
return;
}
try {
final Localpart username = jid.getLocalpart();
final AbstractXMPPConnection connection = new XMPPTCPConnection(
mSettings.getConnectionConfiguration(InfoAndSettings.this));
showToast("Connecting to server", Toast.LENGTH_SHORT);
connection.connect();
AccountManager accountManager = AccountManager.getInstance(connection);
showToast("Connected, trying to create account", Toast.LENGTH_SHORT);
accountManager.createAccount(username, password);
connection.disconnect();
} catch (Exception e) {
LOG.i("registerAccount", e);
showToast("Error creating account: " + e, Toast.LENGTH_LONG);
return;
}
showToast("Account created", Toast.LENGTH_SHORT);
}
private final void showToast(final String text, final int duration) {
InfoAndSettings.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(InfoAndSettings.this, text, duration).show();
}
});
}
}).start();
}
示例15: getConnection
import org.jivesoftware.smack.AbstractXMPPConnection; //导入依赖的package包/类
AbstractXMPPConnection getConnection() throws SmackException.NotConnectedException;