本文整理匯總了Java中org.jivesoftware.smack.tcp.XMPPTCPConnection類的典型用法代碼示例。如果您正苦於以下問題:Java XMPPTCPConnection類的具體用法?Java XMPPTCPConnection怎麽用?Java XMPPTCPConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XMPPTCPConnection類屬於org.jivesoftware.smack.tcp包,在下文中一共展示了XMPPTCPConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: controlNotificationAlarm
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
private void controlNotificationAlarm(boolean torchMode) {
final XMPPTCPConnection connection = mXmppManager.getXmppConnection();
final EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify();
if (fullThingJid == null) return;
SetBoolData setTorch = new SetBoolData(Constants.NOTIFICATION_ALARM, torchMode);
IoTControlManager ioTControlManager = IoTControlManager.getInstanceFor(connection);
LOGGER.info("Trying to control " + fullThingJid + " set torchMode=" + torchMode);
try {
final IoTSetResponse ioTSetResponse = ioTControlManager.setUsingIq(fullThingJid, setTorch);
} catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not control thing: " + e, Toast.LENGTH_LONG).show());
LOGGER.log(Level.SEVERE, "Could not set data", e);
}
}
示例3: connect
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的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: initOMemoManager
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
private OmemoManager initOMemoManager(XMPPTCPConnection conn, BareJid altUser) {
BareJid user;
if (conn.getUser() != null) {
user = conn.getUser().asBareJid();
} else {
user = altUser;
}
mOmemoStore = OmemoService.getInstance().getOmemoStoreBackend();
int defaultDeviceId = mOmemoStore.getDefaultDeviceId(user);
if (defaultDeviceId < 1) {
defaultDeviceId = OmemoManager.randomDeviceId();
mOmemoStore.setDefaultDeviceId(user, defaultDeviceId);
}
return OmemoManager.getInstanceFor(conn, defaultDeviceId);
}
示例5: connect
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
public void connect(String hostname, int port, String username, String password) throws Exception {
purgeTask("reconnect");
this.hostname = hostname;
this.serviceName = hostname;
this.port = port;
this.username = username;
this.password = password;
Builder builder = XMPPTCPConnectionConfiguration.builder();
builder.setUsernameAndPassword(username, password);
builder.setServiceName(serviceName);
builder.setServiceName(hostname);
builder.setPort(port);
builder.setSecurityMode(SecurityMode.disabled);
builder.setDebuggerEnabled(true);
XMPPTCPConnectionConfiguration config = builder.build();
connection = new XMPPTCPConnection(config);
connection.connect().login();
roster = Roster.getInstanceFor(connection);
chatManager = ChatManager.getInstanceFor(connection);
roster.addRosterListener(this);
isConnected = true;
// not worth it - always empty right after connect
// getContactList();
broadcastState();
}
示例6: LolChat
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的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();
}
示例7: XmppTransceiver
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
private XmppTransceiver(XMPPTCPConnection connection, PacketFilter messageFilter) {
this.connection = connection;
PacketListener observablePacketListener = new PacketListener() {
@Override
public void processPacket(Packet packet) throws SmackException.NotConnectedException {
pw.swordfish.sms.Message sms;
try {
sms = xmppToSms(Unsafe.<Message>cast(packet));
} catch (MalformedSmsAddress ignored) {
return;
}
for (Observer<pw.swordfish.sms.Message> observer : observers)
observer.onNext(sms);
}
};
this.connection.addPacketListener(observablePacketListener, messageFilter);
}
示例8: 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);
}
示例9: 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);
});
}
示例10: createManagedConnection
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
public XMPPTCPConnection createManagedConnection(XMPPTCPConnectionConfiguration configuration) {
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
ManagedXmppConnection managedConnection = new ManagedXmppConnection(connection);
for (NewManagedConnectionListener newManagedConnectionListener : mNewConnectionListeners) {
newManagedConnectionListener.newConnection(managedConnection);
}
synchronized (managedConnection) {
mManagedConnections.put(connection, managedConnection);
}
return connection;
}
示例11: disconnectConnections
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
void disconnectConnections() {
forAllManagedConnections(new WithXmppConnection<XMPPTCPConnection>() {
@Override
public void withXmppConnection(XMPPTCPConnection connection, ManagedXmppConnection managedXmppConnection) {
connection.disconnect();
}
});
}
示例12: forAllManagedConnections
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
void forAllManagedConnections(WithXmppConnection<XMPPTCPConnection> withXmppConnection) {
synchronized (mManagedConnections) {
for (ManagedXmppConnection<XMPPTCPConnection> managedXmppConnection : mManagedConnections.values()) {
final XMPPTCPConnection connection = managedXmppConnection.getConnection();
if (connection == null) {
mManagedConnections.remove(managedXmppConnection);
continue;
}
withXmppConnection.withXmppConnection(connection, managedXmppConnection);
}
}
}
示例13: claimButtonClicked
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
private void claimButtonClicked(final Thing thing) {
final XMPPTCPConnection connection = mXmppManger.getXmppConnection();
if (connection == null) {
showInGui("Not connection available");
return;
}
if (!connection.isAuthenticated()) {
showInGui("Connection not authenticated");
return;
}
IoTDiscoveryManager ioTDiscoveryManager = IoTDiscoveryManager.getInstanceFor(connection);
IoTClaimed iotClaimed;
try {
iotClaimed = ioTDiscoveryManager.claimThing(mRegistry, thing.getMetaTags(), true);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
showInGui("Could not claim because " + e);
LOGGER.log(Level.WARNING, "Could not register", e);
return;
}
EntityBareJid claimedJid = iotClaimed.getJid().asEntityBareJidIfPossible();
if (claimedJid == null) {
throw new IllegalStateException();
}
Settings settings = Settings.getInstance(this);
settings.setClaimedJid(claimedJid);
showInGui("Thing " + claimedJid + " claimed.");
runOnUiThread(() -> {
finish();
});
}
示例14: performReadOut
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
private void performReadOut() {
XMPPTCPConnection connection = mXmppManager.getXmppConnection();
EntityFullJid fullThingJid = mXmppManager.getFullThingJidOrNotify();
if (fullThingJid == null) return;
LOGGER.info("Requesting read out from " + fullThingJid);
IoTDataManager iotDataManager = IoTDataManager.getInstanceFor(connection);
final List<IoTFieldsExtension> res;
try {
res = iotDataManager.requestMomentaryValuesReadOut(fullThingJid);
} catch (SmackException.NoResponseException | XMPPErrorException | SmackException.NotConnectedException |InterruptedException e) {
mXmppManager.withMainActivity((ma) -> Toast.makeText(mContext, "Could not perform read out: " + e, Toast.LENGTH_LONG).show());
LOGGER.log(Level.WARNING, "Could not perform read out", e);
return;
}
final List<? extends IoTDataField> dataFields = res.get(0).getNodes().get(0).getTimestampElements().get(0).getDataFields();
mXmppManager.withMainActivity((ma) -> {
ma.mIotSensorsLinearLayout.removeAllViews();
for (IoTDataField field : dataFields) {
IotSensorView iotSensorView = new IotSensorView(ma, field.getName(), field.getValueString());
ma.mIotSensorsLinearLayout.addView(iotSensorView);
}
});
}
示例15: login
import org.jivesoftware.smack.tcp.XMPPTCPConnection; //導入依賴的package包/類
public void login(String user, String pass, StatusItem status, String username)
throws XMPPException, SmackException, IOException, InterruptedException {
Log.i(TAG, "inside XMPP getlogin Method");
long l = System.currentTimeMillis();
XMPPTCPConnection connect = connect();
if (connect.isAuthenticated()) {
Log.i(TAG, "User already logged in");
return;
}
Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));
l = System.currentTimeMillis();
connect.login(user, pass);
Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));
Log.i(TAG, "login step passed");
Presence p = new Presence(Presence.Type.available);
p.setMode(Presence.Mode.available);
p.setPriority(24);
p.setFrom(connect.getUser());
if (status != null) {
p.setStatus(status.toJSON());
} else {
p.setStatus(new StatusItem().toJSON());
}
// p.setTo("");
VCard ownVCard = new VCard();
ownVCard.load(connect);
ownVCard.setNickName(username);
ownVCard.save(connect);
PingManager pingManager = PingManager.getInstanceFor(connect);
pingManager.setPingInterval(150000);
connect.sendPacket(p);
}