1

in my application I'm trying to access node created on server using smack library.When i run the code in java it does not give me any error.But when i try the same using android project at that time lo-gin is successful but while accessing node it's giving me error 404.

I have added Asmack jar file in build path.Please help me...I'm stuck...

    public class ChatApplicationActivity extends Activity {
    /** Called when the activity is first created. */
    static XMPPConnection connection;
    TextView textView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

      textView=(TextView)findViewById(R.id.textView);

      try {
          ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider()); 
            ConnectionConfiguration cc = new ConnectionConfiguration("192.168.1.113", 5222, "192.168.1.113");
            connection = new XMPPConnection(cc);
            connection.connect();
             SASLAuthentication.supportSASLMechanism("PLAIN", 0);
            connection.login("test","test");
            Log.i("debug", "login success");


    //      MySmackClient client=new MySmackClient();
    //        client.login("test1","test1");

          //client.displayBuddyList();

         // CreateNode node = new CreateNode(connection);
         subNode("test@eze-dem-113","testNode5");
         // String talkTo = br.readLine();

          System.out.println("-----");
        //  System.out.println("All messages will be sent to " + talkTo);
          System.out.println("Enter your message in the console:");
          System.out.println("-----\n");
    } catch (XMPPException e) {

        e.printStackTrace();
    }
    }


    public void subNode(String JID,String nodeName)
    {


     PubSubManager mgr = new PubSubManager(connection);
   //    String pubSubAddress = "pubsub." + connection.getServiceName();
   //    PubSubManager manager = new PubSubManager(connection, pubSubAddress);
       try {
          // Get the node
         // Node eventNode = manager.getNode("testNode5");  //i always get error here

          LeafNode node = (LeafNode)mgr.getNode(nodeName);

        node.addItemEventListener(new ItemEventCoordinator());

        node.subscribe(JID);
        } catch (XMPPException e) {

            e.printStackTrace();
        }
    }

    class ItemEventCoordinator  implements ItemEventListener
    {
       int track =0;
        public void handlePublishedItems(ItemPublishEvent items)
        {
           System.out.println("Got Publish:"+track);
            PayloadItem<SimplePayload> item = (PayloadItem<SimplePayload>) items.getItems().get(0);

            SimplePayload payload = item.getPayload();

            String payloadData = payload.toXML();
            System.out.println(payloadData);

        }
    }
}
Robin
  • 24,062
  • 5
  • 49
  • 58
android
  • 386
  • 1
  • 8
  • 21

1 Answers1

0

What version of Smack are you using. I don't think asmack is being maintained, so it is probably out of sync with Smack proper.

One suggestion would be to change

 PubSubManager mgr = new PubSubManager(connection);

for the lines you have commented out

 String pubSubAddress = "pubsub." + connection.getServiceName();
 PubSubManager manager = new PubSubManager(connection, pubSubAddress);

Smack was changed to default to that pubsub address, asmack probably doesn't have that change. If you use the more explicit constructor, it will be consistent in both environments.

Robin
  • 24,062
  • 5
  • 49
  • 58
  • For alternatives of aSmack on googlecode see also this question http://stackoverflow.com/questions/4769020/android-and-xmpp-currently-available-solutions – Flow Feb 09 '12 at 09:58