2

I have an XMPP application where two clients interact (1) a bot programmed with Smack (Scala/Java) and (2) a GUI chat client programmed in strophe (Javascript).

The app needs to exchange custom XML (e.g., as shown below)

<myPacket>
   <response type='sensorData'>
      <temperature units='Kelvin'>
         234
      </temperature>
   </response>
</myPacket>

What is the best way to exchange data? The following are what I could come up with:

1) Write custom XMPP stanzas

2) Embed my XML in currently defined stanzas (e.g, in message or iq)

3) For smack, use the Message.get(set)Property to read/write custom data.

No. 3) is ruled out because it requires that both clients understand Java objects and use the same library (Smack).

Kindly point me to any other questions addressing the same issue.

[EDIT:] After doing some research, I found that Dataforms (XEP-0004) is the easiest way to do it, provided your library supports it.

Jus12
  • 17,824
  • 28
  • 99
  • 157
  • 2
    Send custom xml data from your client using child element in respective XMPP stanza's with your own namespace. E.g. ... . Such stanza's will in turn received by your client bot without any other config needs. – Abhinav Singh Nov 19 '10 at 07:05
  • Thanks for the comment. I eventually decided to use the child element with dataforms. – Jus12 Dec 14 '10 at 19:21
  • I found the hard way that dataforms (XEP-004) is not fully complete in smack. It is better to use custom encoding (e.g,, JSON inside a message stanza). This is what we ended up doing everywhere. – Jus12 Sep 20 '12 at 00:50

1 Answers1

3

That largely depends on how the data is going to be used. My rule of thumb is that if I'm only passing around key-value pairs (simple data) then I would go for the property feature in Smack. But the property feature can only be used in Message. For some reason, the property extension does not use Smack's provider architecture but its hardcoded into Packet and PacketParserUtils class. So if you can't reuse it in IQ or Presence packets.

If you are going to use anything more that a key-value pair, then you should write a provider for your custom stanza. It's a bit of work but once you've implemented the marshalling/unmarshalling then your custom stanza works pretty much everywhere in the Smack framework. See Smacks provider architecture for details.

I did blog about writing provider in one of my post. It's not the main trust of the post but hope you find it helpful as well.

Chuk Lee
  • 3,570
  • 22
  • 19
  • Thanks for the answer. I think the Smack property feature is restricted to Smack-only code, so that is not a good option. I'll check out the provider architecture for implementing own stanzas. The blog entry is useful. – Jus12 Nov 23 '10 at 17:42