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 jabber.org
DiscoverItems items = mgr.discoverItems(“jabber.org”);
Iterator<DiscoverItems.Item> iter = items.getItems();
while (iter.hasNext()) {
   DiscoverItems.Item i = iter.next();
   System.out.println(i.toXML());
}

This will produce the following from jabber.org

<item jid=”proxy.eu.jabber.org”/>
<item jid=”conference.jabber.org” name=”Multi-User Chat”/>

Once you have this list, you can now use the JID enteries to retrieve other services. For example, notice that jabber.org supports multiuser chat (MUC) with JID conference.jabber.org. 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(ServiceDiscoveryManager.java:495)
   …

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

SASLAuthentication.supportSASLMechanism(“PLAIN”);
ConnectionConfiguration config = new ConnectionConfiguration(
      “talk.google.com”, 5222, “gmail.com”);
XMPPConnection conn = new XMPPConnection(config);
conn.connect();
//Note you MUST have ‘@gmail.com’ to login
conn.login(“gmail_id@gmail.com”, “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.

About these ads

3 Responses to Discovering Services

  1. thaiduy says:

    Hi.
    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:

    http://pastebin.com/2PzMBSJC

    Thanks in advance.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: