【问题标题】:How to detect an error while sending a chat using Smack如何在使用 Smack 发送聊天时检测错误
【发布时间】:2013-04-07 19:11:38
【问题描述】:

我正在使用 smack 发送聊天消息。在测试时我发现,当网络不可用时,API 不会抛出任何异常。

我的代码:

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  */

我应该添加任何侦听器来捕获异常吗?

【问题讨论】:

标签: java xmpp chat smack


【解决方案1】:

您不会收到异常,因为它是异步调用。如果您想知道连接是否已断开,则必须向该连接注册一个 ConnectionListener。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2015-10-04
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    相关资源
    最近更新 更多