Discovering Services

In my previous blog entry, I mentioned that you need to find out if a server supports pubsub. To do that you can use Pidgin’s XMPP Service Discovery Plugin. You can also use Smack to retrieve a list of supported services. Here is the code snippet that will retrieve a list of items/services that a server supports

//Connect and login
XMPPConnection conn = …

ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(conn);
//Assuming that we are querying
DiscoverItems items = mgr.discoverItems(“”);
Iterator<DiscoverItems.Item> iter = items.getItems();
while (iter.hasNext()) {
   DiscoverItems.Item i =;

This will produce the following from

<item jid=””/>
<item jid=”” name=”Multi-User Chat”/>

Once you have this list, you can now use the JID enteries to retrieve other services. For example, notice that supports multiuser chat (MUC) with JID We can now use this JID to get a list of rooms, configurations, etc.

Connecting to Google Talk produce the following

Exception in thread “main” feature-not-implemented(501)
   at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverItems(

Clearly Google has implemented a no frills server; Google Talk only support 1 to 1 chat and nothing else. BTW to connect to Google talk, use the following code snippet

ConnectionConfiguration config = new ConnectionConfiguration(
      “”, 5222, “”);
XMPPConnection conn = new XMPPConnection(config);
//Note you MUST have ‘’ to login
conn.login(“”, “your password”);

And finally here is the list of services from an instance of openfire running on my notebook

<item jid=”pubsub.batcomputer” name=”Publish-Subscribe service”/>
<item jid=”search.batcomputer” name=”User Search”/>
<item jid=”conference.batcomputer” name=”Public Chatrooms”/>
<item jid=”proxy.batcomputer” name=”Socks 5 Bytestreams Proxy”/>

Notice that pubsub JID which is exactly the service we were trying to connect with PubSubManager.


3 Responses to Discovering Services

  1. thaiduy says:

    Thanks for your post.
    Unfortunately i have some troubles with Discovering Services. May you can help?

    I am using asmack for Android, and i tried to retrieve available DiscoverItems from server by following xml:

    But server only responsed like this:

    There is no item in iq tag, instead of some things like “yahoo”, “icq”, etc which the server actually supports. Do you have any ideas about it?

    Thanks in advance.

  2. thaiduy says:

    I’m sorry about posting code without HTML encoded. Here the code from pastebin:

    Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: