在android中使用Asmack时出现404错误
在我的应用程序中,我尝试使用 smack 库访问在服务器上创建的节点。当我在 java 中运行代码时,它不会给我任何错误。但是当我当时使用 android 项目尝试相同的操作时,lo-gin 是成功的,但是访问节点时出现错误 404。
我已在构建路径中添加了 Asmack jar 文件。请帮助我...我被困住了...
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);
}
}
}
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是哪个版本的 Smack。我认为 asmack 没有得到维护,所以它可能与 Smack 不同步。
一个建议是更改
您注释掉的行,
Smack 已更改为默认为该 pubsub 地址,asmack 可能没有该更改。如果您使用更显式的构造函数,它将在两种环境中保持一致。
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
for the lines you have commented out
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.