I had a minimal working IM with smac 3.x.x for android
After upgrading to smac 4.4.6 I am getting a lot of issues.
I am using hot-chilli.net server.
The API documents are good but I need a simple minimal working example that works with smac 4.4.6. specifically I need to connect, log in, send and listen to incoming messages. I am trying to just log incoming messages to logcat.
All the tutorial I found online deal with older versions of smac.
if you could point somewhere with a basic sample code that works with 4.4.6 I will greatly appreciate it.
The following works with Openfire started in ‘demoboot’ mode (which automatically creates the user accounts that are used by this example). You can obviously also replace this with your own users.
Note that this example disables important security features. You should not use this for anything important!
public class TestClients
public static void main(String args) throws Exception
//SmackConfiguration.DEBUG = true;
final XMPPTCPConnectionConfiguration configSender = XMPPTCPConnectionConfiguration.builder()
final XMPPTCPConnectionConfiguration configReceiver = XMPPTCPConnectionConfiguration.builder()
final XMPPTCPConnection connectionSender = new XMPPTCPConnection(configSender);
final XMPPTCPConnection connectionReceiver = new XMPPTCPConnection(configReceiver);
connectionSender.setUseStreamManagement(false); // To reduce output in the debug log.
connectionReceiver.setUseStreamManagement(false); // To reduce output in the debug log.
// Listen for incoming messages.
connectionReceiver.addAsyncStanzaListener((stanza -> System.out.println("Received: " + ((Message) stanza).getBody())), MessageWithBodiesFilter.INSTANCE);
// Construct and send message.
final Message message = MessageBuilder.buildMessage()
Thank you very much. Unfortunately I am not even able to connect anymore.
It worked ok with smack 3.4.0 but I needed the message delivery status functionality so I upgraded to smack 4.4.6. I tried using your example to just connect my android app to hot-chilli server but it times out.
That sounds like a networking issue. Are you sure that you have provided the correct XMPP domain name, and host (alternatively, you can remove the
setHost method call and let Smack look up the correct value itself).
Without any kind of debug logging, it’s hard to tell what’s going wrong for you.
Thank you. got it to work again. I had to implement stanza parsing error callback. it was disconnecting because of a lot of unparsable stanzas. logging these stanzas yielded stuff like :“name: hot-chilli Skype transport”, “instagram transport”, “hangout trastport” etc. I have no idea where they come from. A side question: I’m implementing messaging in ways of using the Chat class. I also see code, as yours as well not using a Chat class but rather an asynchronous stanza listener. Are both equivalent? Obviously you can get more data out a stanza but other than that?