本文介绍了发送和接收定制的XMPP智商与aSmack在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我已经实现了一个使用aSmack的XMPP在Android上的聊天。我还能够发送和接收的智商消息。

I have implemented one to one chat using aSmack for XMPP on Android. I am also able to send and receive IQ messages.

的问题是:

我无法发送和接收定制的智商消息。例如,如果我要发送的IQ

I am unable to send and receive custom IQ messages. for example if i want to send an IQ

<iq type='get'
    to='[email protected]/mack'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>

aSmack工作正常,这智商,因为它不是定制的,但如果我修改命名空间这里迪斯科#项目匹配它不会工作,它会发送回服务器的响应,说明

aSmack works fine for this IQ as it is not custom, but if i change the name space here from disco#items to Match it will not work it will send back server a response stating

<error code='503'
       type='cancel'>
<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
</error>

和这种反应是送我的客户。但我试图调试它,我把破发点上的所有接收和发送的数据包code。但它不进入那里。

and this response is send from my client. but i tried to debug it, i put break points on all receiving and sending packets code. but it does not enter there.

我的code,用以接收数据包是:

My code for receiving packet is:

connection.addPacketListener(new PacketListener() {

                @Override
                public void processPacket(Packet p) {
                    // TODO Auto-generated method stub
                    String fromName1 = StringUtils.parseBareAddress(p.getFrom());
                    Log.i("XMPPClient", "Got text [" + p.toXML() + "] from [" + fromName1 + "]");

                    m1=p.getFrom();


                    mHandler.post(new Runnable() {
                        public void run() {
                            setListAdapter();
                            recieve.setText(m1);
                        }
                    });

我想我需要补充一些听众获得自定义响应。可有人指导我通过?

I guess i need to add some listeners to get the custom response. can somebody guide me through that?

推荐答案

在code是不完整的。 addPacketListener()有两个参数。

The code is incomplete. addPacketListener() takes two arguments.

我怀疑你不注册的提供者,在接收端自定义的智商,这就是为什么它返回&LT;服务不可用的xmlns =金塔:IETF:params:一个XML:NS:XMPP协议-stanzas/&GT;

I suspect you don't register a provider for the custom IQ on the receiving side, that's why it returns <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>

您可能需要阅读一些文档:

You may want to read some documentation:

  • Provider Architecture: Packet Extensions and Custom IQ's
  • Brief Tutorial on IQ Providers

这篇关于发送和接收定制的XMPP智商与aSmack在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:13