Chapter 4. Examples
Prev | Part I. JaXMPP V3.2.0 Release Notes | Next

## Chapter 4. Examples

## A very simple client in Groovy (sending and listening for message)

    import tigase.jaxmpp.core.client.BareJID
    import tigase.jaxmpp.core.client.JID
    import tigase.jaxmpp.core.client.SessionObject
    import tigase.jaxmpp.core.client.exceptions.JaxmppException
    import tigase.jaxmpp.core.client.xmpp.modules.chat.Chat
    import tigase.jaxmpp.core.client.xmpp.modules.chat.MessageModule
    import tigase.jaxmpp.core.client.xmpp.stanzas.Message
    import tigase.jaxmpp.j2se.Jaxmpp

    final Jaxmpp contact = new Jaxmpp()

    tigase.jaxmpp.j2se.Presence.initialize(contact);

    contact.getModulesManager().register(new MessageModule());

    contact.getProperties().setUserProperty(SessionObject.USER_BARE_JID, BareJID.bareJIDInstance("admin@atlantiscity"))
    contact.getProperties().setUserProperty(SessionObject.PASSWORD, "admin")

    contact.getEventBus().addHandler(MessageModule.MessageReceivedHandler.MessageReceivedEvent.class,
            new MessageModule.MessageReceivedHandler() {

                @Override
                public void onMessageReceived(SessionObject sessionObject, Chat chat, Message stanza) {
                    System.out.println("message: " + stanza.getBody());
                }
            });

    println("Loging in...");

    contact.login(true)

    if (contact.isConnected()) {
        contact.getModule(MessageModule.class).sendMessage(JID.jidInstance("tigase1@atlantiscity"), "Test", "This is a test")

        Thread.sleep(1 * 10 * 1000)

        contact.disconnect()
    }

Prev | Up | Next
Design | Home | A very simple client in Groovy (direct presence + presence listen)