1
votes

So i have tried a lot the last days...

I built a XMPP Server and a Client for my pc without any problems.

Than i started to create a Client for Android and... yeah.. i just say i just dont want to read more errors..

I read all the things about bugs with XMPP, Android and PubSub. now i built this apk.

I am able to Connect and to stay online. My problem is a cannot build a Node.

So this is my Code:

`

package com.Eis.androidclient;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.PublishItem;
import org.jivesoftware.smackx.pubsub.SimplePayload;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class Client extends Activity {

static {
    XMPPConnection.DEBUG_ENABLED = true;
}

ConnectionConfiguration connConfig = new ConnectionConfiguration(
        "192.168.0.100", 5222);
XMPPConnection connection = new XMPPConnection(connConfig);
String pubSubAddress = "pubsub."+ connection.getServiceName();
PubSubManager manager = new PubSubManager(connection,pubSubAddress);
SimplePayload payload = new SimplePayload("session",
        "pubsub:NewNode:session", "<sessionId>5678</sessionId>");
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null,
        payload);



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    org.jivesoftware.smack.SmackAndroid.init(this);
    Button node = (Button)findViewById(R.id.button1);

    node.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            node();     
        }
    });





    Thread thread = new Thread(){
        public void run(){

            try {
                connection.connect();
                connection.login("tester", "tester");
            } catch (XMPPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    };

    thread.run();
    // putting null for id means you let server generate id
    // you could use publish() for asynchronous call


}

public void node(){


    PubSubManager manager = new PubSubManager(connection);
    LeafNode myNode = null;

   // manager.discoverNodes("NewNode");
    try {
        manager.getNode("NewNode");
        System.out.println("found");
        manager.deleteNode("NewNode");
        System.out.println("delete");
    } catch(XMPPException e){
        System.out.println("nothing to do");
        e.printStackTrace();
    }
    try{
        myNode = manager.createNode("NewNode2");
        System.out.println("created");
    } catch (XMPPException e) {
        System.out.println("nothing created");
        e.printStackTrace();
    }




    // you could use publish() for asynchronous call

//      try {
//          myNode.send(item);
//          System.out.println("versendet");
//      } catch (XMPPException e) {
//          System.out.println("wird nicht gesendet");
//          e.printStackTrace();
//      }



}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

} `

My App is running on a VM 2.3.3 so there shouldn't be any thread problems.

and here are the error logs

07:20:48 PM RCV (1079090656): <iq type="error" id="s1YUr-9" from="pubsub.nils-lappi" to="tester@nils-lappi/Smack"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node="NewNode2"/></pubsub><error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

so i dont know why there is a conflict but it seems the rest is ok

error code because of conflict: at org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)

Hopefully someone here can help me...

1
ahh just forgotten. I think the Error is here "manager.getNode("NewNode");"Nils Lütkefent

1 Answers

0
votes

The node NewNode2 already exists and you are trying to create it again.

NOTE: You can simplify your creation of the PubsubManager to just

new PubsubManager(connection);

The usage of pubsub as the service name is actually the default.