1

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='ssmack@web.mystudios.com/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?

Flow
  • 23,572
  • 15
  • 99
  • 156
Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55
  • @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](http://chat.stackoverflow.com/rooms/68853/trying-to-learn) to help me, Thanks – nawaab saab Jan 19 '15 at 09:59
  • i am facing a problem in sending and receiving message on android device from xmpp server using asmack, Can you come over this [link](http://chat.stackoverflow.com/rooms/68853/trying-to-learn) to help me, Thanks – nawaab saab Jan 19 '15 at 09:59

2 Answers2

1

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:

Flow
  • 23,572
  • 15
  • 99
  • 156
-1

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.

vitalyster
  • 4,980
  • 3
  • 19
  • 27