subscribe part

by asdfas on October 15th, 2009
No notes
Syntax: No syntax
Show lines - Hide lines - Show in textbox - Download
package org.jivesoftware.smackx;
 
import java.util.Iterator;
import java.util.List;
 
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;
 
public class TestSubscriber {
 
 
 
 
	public static void main(String[] args) throws XMPPException{
		  XMPPConnection.DEBUG_ENABLED = true;
 
		ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222);
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(true);
 
 
		  XMPPConnection connection = new XMPPConnection(config);
	        // Connect to the server
	        connection.connect();
	        // Log into the server
	        connection.login("test", "password");
 
 
 
 
 
	        PubSubManager manager = new PubSubManager(connection, "computer");
 
 
		Node eventNode = manager.getNode("ghost");  //i always get error here
 
 
		ItemEventListener myListener = new ItemEventListener() {
 
			public void handlePublishedItems(ItemPublishEvent items) {
				// TODO Auto-generated method stub
				System.out.println("result="+items.getItems().toString());
 
 
			}
 
	    };
 
 
 
 
 
        eventNode.addItemEventListener(myListener);
 
        eventNode.subscribe("admin");
	}
 
}
 

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS