所以我在最后几天尝试了很多......
我为我的电脑构建了一个XMPP服务器和一个客户端,没有任何问题。
我开始为Android创建一个客户端...是的..我只是说我只是不想读更多错误..
我通过XMPP,Android和PubSub阅读了有关错误的所有内容。现在我建立了这个apk。
我可以连接并保持在线状态。我的问题是无法构建节点。
所以这是我的代码:
`
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;
}
} `
我的应用程序在VM 2.3.3上运行,因此不应存在任何线程问题。
以下是错误日志
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>
所以我不知道为什么会有冲突,但似乎其余的都没问题
错误代码因冲突:
at org.jivesoftware.smackx.pubsub.packet.SyncPacketSend.getReply(SyncPacketSend.java:53)
希望有人可以帮助我...
答案 0 :(得分:0)
节点 NewNode2 已经存在,您正在尝试再次创建它。
注意:您可以将PubsubManager的创建简化为
new PubsubManager(connection);
使用 pubsub 作为服务名称实际上是默认值。