1
votes

I'm trying to have my android app to be able to send and receive xmpp message using smack but it does not work and the connect command does not return. I have seen several code example but Smack has new versions and the syntax has changed so I might be doing something wrong :

in my build.graddle file I use :

    compile "org.igniterealtime.smack:smack-android-extensions:4.3.0"
    compile "org.igniterealtime.smack:smack-tcp:4.3.0"

I'm trying to send a message from [email protected] to [email protected] I'm trying to connect using hot-chilli.net (Idon't mind using some other server))

everything seems to go well until connection.connect() after which the script does not return without triggering any exception.

Please tell me what I'm doing wrong

TIA

public void sendxmpp(){

XMPPTCPConnectionConfiguration config = null;
    try {
        XMPPTCPConnectionConfiguration.Builder configbuilder = XMPPTCPConnectionConfiguration.builder();
        configbuilder.setUsernameAndPassword("myaccount321","myaccount321pw");
                
        DomainBareJid serviceName = JidCreate.domainBareFrom("hot-chilli.net");
        configbuilder.setServiceName(serviceName);
        configbuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
        configbuilder.setHost("jabber.hot-chilli.net");       
        configbuilder.setPort(8222);
        config=configbuilder.build();
        AbstractXMPPConnection connection = new XMPPTCPConnection(config);
        try {
            connection.connect();
            } 
       catch (SmackException e) {
             e.printStackTrace();
            } 
       catch (IOException e) {
            e.printStackTrace();
        } 
       catch (XMPPException e) {
            e.printStackTrace();
        } 
       catch (InterruptedException e) {
            e.printStackTrace();
        }
       connection.login();

       ChatManager chatManager = ChatManager.getInstanceFor(connection);
        
       EntityBareJid jid = JidCreate.entityBareFrom("[email protected]");
       Chat chat = chatManager.createChat(jid);
        
       chat.sendMessage("Hello");
        

      } 
      catch (Exception e) {
        
     }
  } 
    
    
1

1 Answers

0
votes

OK I got it, the connection process has to be done in its own thread.