Java Code Examples for org.jivesoftware.smack.tcp.XMPPTCPConnection#disconnect()

The following examples show how to use org.jivesoftware.smack.tcp.XMPPTCPConnection#disconnect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        if (!supportsIbr(connection))
            return false;

        AccountManager accountManager = AccountManager.getInstance(connection);
        accountManager.createAccount(username, password);
        return true;
    } finally {
        connection.disconnect();
    }
}
 
Example 2
Source File: IoT.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void iotScenario(String dataThingJidString, String dataThingPassword, String readingThingJidString,
        String readingThingPassword, IotScenario scenario) throws Exception {
    final EntityBareJid dataThingJid = JidCreate.entityBareFrom(dataThingJidString);
    final EntityBareJid readingThingJid = JidCreate.entityBareFrom(readingThingJidString);

    final XMPPTCPConnectionConfiguration dataThingConnectionConfiguration = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword(dataThingJid.getLocalpart(), dataThingPassword)
            .setXmppDomain(dataThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled)
            .enableDefaultDebugger().build();
    final XMPPTCPConnectionConfiguration readingThingConnectionConfiguration = XMPPTCPConnectionConfiguration
            .builder().setUsernameAndPassword(readingThingJid.getLocalpart(), readingThingPassword)
            .setXmppDomain(readingThingJid.asDomainBareJid()).setSecurityMode(SecurityMode.disabled)
            .enableDefaultDebugger().build();

    final XMPPTCPConnection dataThingConnection = new XMPPTCPConnection(dataThingConnectionConfiguration);
    final XMPPTCPConnection readingThingConnection = new XMPPTCPConnection(readingThingConnectionConfiguration);

    dataThingConnection.setReplyTimeout(TIMEOUT);
    readingThingConnection.setReplyTimeout(TIMEOUT);

    dataThingConnection.setUseStreamManagement(false);
    readingThingConnection.setUseStreamManagement(false);

    try {
        dataThingConnection.connect().login();
        readingThingConnection.connect().login();
        scenario.iotScenario(dataThingConnection, readingThingConnection);
    } finally {
        dataThingConnection.disconnect();
        readingThingConnection.disconnect();
    }
}
 
Example 3
Source File: XmppTools.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static boolean supportsIbr(DomainBareJid xmppDomain) throws SmackException, IOException, XMPPException,
        InterruptedException, KeyManagementException, NoSuchAlgorithmException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        return supportsIbr(connection);
    } finally {
        connection.disconnect();
    }
}
 
Example 4
Source File: DoX.java    From Smack with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws XMPPException, SmackException, IOException, InterruptedException {
    SmackConfiguration.DEBUG = true;

    XMPPTCPConnection connection = new XMPPTCPConnection(args[0], args[1]);
    connection.setReplyTimeout(60000);

    connection.connect().login();

    DnsOverXmppManager dox = DnsOverXmppManager.getInstanceFor(connection);

    Jid target = JidCreate.from("[email protected]/listener");
    Question question = new Question("geekplace.eu", Record.TYPE.A);

    DnsMessage response = dox.query(target, question);

    // CHECKSTYLE:OFF
    System.out.println(response);
    // CHECKSTYLE:ON

    connection.disconnect();
}