简体   繁体   中英

How to detect an error while sending a chat using Smack

I'm using smack to send a chat message. While testing i figured out that, when the network is unavilable, the API does not throw any exceptions.

my code :

Chat chat = connection.getChatManager().createChat(
        "abc@gmail.com", new MessageListener() {

            @Override
            public void processMessage(Chat arg0, Message arg1) {
                System.out.println(arg1.getFrom() + "  says  " + arg1.getBody());

            }
        });
// I Put a break point here and deliberately disable the network.
// But the following line is not throwing the XMPPException

chat.sendMessage("smack says hi.."); /* Send the message  */

Should i add any listeners to capture the exception?

You won't get an exception since it is an asynchronous call. If you want to know if the connection has been dropped, you will have to register a ConnectionListener with the Connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM