1
votes

Background:

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

The issue is:

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

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.

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?

2
@Flow i am facing a problem in sending and receiving message on android device from xmpp server using asmack, Can you come over this link to help me, Thanksnawaab saab
i am facing a problem in sending and receiving message on android device from xmpp server using asmack, Can you come over this link to help me, Thanksnawaab saab

2 Answers

1
votes

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

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:

-1
votes

You need to use ServiceDiscoveryManager and register your custom namespace like this:

ServiceDiscoveryManager sm = ServiceDiscoveryManager.getInstanceFor(connection);
sm.addFeature("your:namespace");

Look at Smack sources, all internal IQ handlers add themselves as feature, match incoming query packets by namespace and build result or error reply.