我正在尝试使用asmack库在Android上实现一个简单的jabber messenger.这是代码:
public boolean login()
{
if (connection != null && connection.isConnected())
{
Log.i("XMPP", connection.getHost());
try
{
connection.login(USERNAME, PASSWORD);
}
catch (XMPPException e)
{
e.printStackTrace();
return false;
}
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我在connection.login()之后得到的异常(连接看起来很好):
service-unavailable(503)
at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:77)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:239)
at org.jivesoftware.smack.Connection.login(Connection.java:353)
at com.someapp.networking.XMPPMessenger.login(XMPPMessenger.java:60)
at com.someapp.XMPPService.onCreate(XMPPService.java:33)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
at android.app.ActivityThread.access$3200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1917)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
可能是什么错误?
StackOverflow的好人,请帮忙.我在我的ubuntu机器上设置了一个ejabberd服务器,添加了虚拟主机,设置了{access,register,[{allow,all}]}.并注册了一个管理员帐户.我不是linux大师,但我已经设法做了这个基本的设置.现在,从我的Win 7机器,使用Pidgin,我可以以管理员身份登录并可以访问许多管理功能.最重要的是我可以在服务器上创建新用户.问题是我不能用我的Android客户端使用asmack库来做到这一点.我可以建立连接和登录,但是当我尝试通过客户经理或通过发送IQ数据包注册新用户时,我得到禁止(403)响应错误.
AccountManager am = new AccountManager(connection);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", "my_user_name");
attributes.put("password", "my_password");
attributes.put("email", "foo@foo.com");
attributes.put("name", "my_full_name");
am.createAccount("my_user_name", "my_password", attributes);
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
// attributes.put("username", username);
// attributes.put("password", password);
// reg.setAttributes(attributes);
reg.addAttribute("username", username);
reg.addAttribute("password", password);
reg.addAttribute("email", email);
reg.addAttribute("name", fullName);
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
Run Code Online (Sandbox Code Playgroud)
有没有人有类似的问题或者可以告诉我我做错了什么?
谢谢
这是我的LogCat
10-10 10:00:26.249: DEBUG/StatusBarPolicy(1639): [BRIGHTHY] curNetwork=22003 curHPLMN=22003
10-10 10:00:26.839: INFO/System.out(21277): 10:00:26 AM SENT (1080244736): <iq id="fMJxx-4" …Run Code Online (Sandbox Code Playgroud) 我是堆栈上的新用户,但我在aSmack库3.2.1 for android中遇到MultiUserChat问题.我正在使用"gtalk.google.com"服务器.这是一个简单的例子,我只是房间里的一个:
String room="myConference@conference.jabber.org";
MultiUserChat muc = new MultiUserChat(connection,room);
muc.join(userNameInRoom);
muc.addMessageListener(new PacketListener()
{
@Override
public void processPacket(Packet packet)
{
...
}
});
Run Code Online (Sandbox Code Playgroud)
后:
muc.sendMessage("Text message");
Run Code Online (Sandbox Code Playgroud)
在日志中:
DEBUG/SMACK(281): 06:46:29 PM SENT (1140866576): <message id="gsMe7-18"
to="myConference@conference.jabber.org" type="groupchat"><body>Text message
</body></message>
DEBUG/SMACK(281): 06:46:29 PM RCV (1140866576): <message
from="myConference@conference.jabber.org/userNameInRoom" to="userName"
type="groupchat"><body>Text message</body></message>
Run Code Online (Sandbox Code Playgroud)
结果:"短信",它是正确的,但随后:
我再次收到了"短信"的存在:
DEBUG/SMACK(281): 06:54:12 PM RCV (1140866576): <presence
from="myConference@conference.jabber.org/userNameInRoom" to="userName"><x xmlns=
"vcard-temp:x:update"><photo/></x><x xmlns="http://jabber.org/protocol/muc#user">
<item affiliation="owner" role="moderator"/><status code="110"/></x></presence>
DEBUG/SMACK(281): 06:54:12 PM RCV (1140866576): <message
from="myConference@conference.jabber.org/userNameInRoom" to="userName"
type="groupchat"><body>Text message</body><delay stamp="2012-02-15T17:46:31Z"
from="myConference@conference.jabber.org" xmlns="urn:xmpp:delay"/><x
stamp="20120215T17:46:31" from="myConference@conference.jabber.org" …Run Code Online (Sandbox Code Playgroud) 您好我在使用asmack库注册时出错.注册代码
Log.d(TAG, "creating new server account...");
AccountManager am = new AccountManager(connection);
Log.i("Registration Details:","UaerName = "+config.userName + " Password is ==" + config.password);
am.createAccount(config.userName, config.password);
Run Code Online (Sandbox Code Playgroud)
我得到的日志:
<main>09-14 12:18:08.132: D/yaxim.SmackableImp(5933): creating new server account...
09-14 12:18:08.142: D/SMACK(5933): 12:18:08 PM SENT (1089044856): <iq id="Ii5WG-0" to="myHost" type="get"><query xmlns="jabber:iq:register"></query></iq>
09-14 12:18:08.522: D/SMACK(5933): 12:18:08 PM RCV (1089044856): <iq type="result" id="Ii5WG-0" from="myHost"><query xmlns="jabber:iq:register"><username/><password/><email/><name/><x xmlns="jabber:x:data" type="form"><title>XMPP Client Registration</title><instructions>Please provide the following information</instructions><field var="FORM_TYPE" type="hidden"><value>jabber:iq:register</value></field><field var="username" type="text-single" label="Username"><required/></field><field var="name" type="text-single" label="Full name"/><field var="email" type="text-single" label="Email"/><field var="password" type="text-private" label="Password"><required/></field></x></query></iq>
09-14 …Run Code Online (Sandbox Code Playgroud) 我正在尝试为asmack数据包编写一个监听器.最终发生的事情是监听器有时只是没有得到数据包并处理它.以下是一些代码:
try {
XMPPMethods.getConnection().addPacketListener( new PacketListener() {
@Override
public synchronized void processPacket(Packet packet) {
if (packet.getPacketID().equals(lastCustomIQId)) {
android.os.Message msg = new android.os.Message();
msg.obj = privateData;
msg.what = XMPPMethods.ADD_CONTACT_RESULTS;
AddContact.addContactHandler.sendMessage(msg);
}
}
}, new PacketIDFilter(lastCustomIQId));
Run Code Online (Sandbox Code Playgroud)
请注意,这是在asInctask的doInBackground(string ... params)部分内部.
数据包正在使用以下方式发送:
JIDIQ.setPacketID(lastCustomIQId);
JIDIQ.setFrom(XMPPMethods.getCurrentUserFullUserName());
JIDIQ.setType(Type.GET);
XMPPMethods.getConnection().sendPacket(JIDIQ);
Run Code Online (Sandbox Code Playgroud)
JIDIQ是一个asmack IQ.这段代码大部分时间都正确运行.但有时PacketListener只是没有收到发送的数据包.我想知道我是否应该使用PacketCollector,或者如果监听器以某种方式死亡.有谁知道为什么这不会收到数据包?任何有关此主题的知识将不胜感激!
基本上我有一个运行整个项目的Main类.代码工作正常但是一旦App没有聚焦它变得不活跃.我想知道如何将它作为一项服务.一个会在启动时启动.
该应用程序将是用于通知的单向消息系统.IE
桌面客户端 - > Openfire服务器 - > Android XMPP服务 - >存储(DB) - >用于显示的Android GUI
正如我所说,代码正在运行(连接,登录,接收),但不是服务.
我可以使用BEEM源,但它太功能和隔行扫描.我是一个轻量级的服务.
代码:
public class MainActivity extends Activity {
public static final String HOST = "fire.example.com";
public static final int PORT = 5222;
public static final String SERVICE = "example.com";
public static final String USERNAME = "metest@fire.example.com";
public static final String PASSWORD = "mepass";
private XMPPConnection connection;
private ArrayList<String> messages = new ArrayList<String>();
private Handler mHandler = new Handler();
private ListView listview;
/** Called when …Run Code Online (Sandbox Code Playgroud) 如何从MUC房间获取DiscussionHistoryMultiUserChat?我可以使用一个Smack库创建MultiUserChat实例和房间,现在我想显示房间里发生的所有先前的对话.
有同样经验的人请帮助我.谷歌搜索了很多关于这一点,但我仍然没有得到任何适当的文件/解释.
我在android项目中使用asmack最新版本(asmack-android-8-source-0.8.3),我有以下代码:
connection.addPacketListener(new PacketListener()
{
@Override
public void processPacket(Packet p)
{
if(p.getPacketID().equals("v3"))
{
Log.e("TAG", p.toXML());
}
}
}, new IQTypeFilter(IQ.Type.RESULT));
Packet iq = new Packet()
{
@Override
public String toXML()
{
String str = "<iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>";
Log.e("TAG", str);
return str;
}
};
//sends <iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>
connection.sendPacket(iq);
Run Code Online (Sandbox Code Playgroud)
在调试器中,响应没问题,这是预期的:
<iq type="result" id="v3" to="minimaal@mrserver/Smack">
<servertime xmlns="urn:xmpp:mrpresence" utc="2013-06-28T11:45:32.380Z" local="2013-06-28T07:45:32.380Z"/>
</iq>
Run Code Online (Sandbox Code Playgroud)
但是包列表器中的p.toXML(),它缺少标签"servertime":
<iq id="v3" to="minimaal@mrserver/Smack" type="result"></iq>
Run Code Online (Sandbox Code Playgroud)
关于我做错的任何建议?
I am working on a chat app using xmpp,As per our requirement we have three server Apache Tomcat 7,ejabbered 2.1.11 and mysql 5.5,
to run xmppbot on tomcat used below library
-Smack-core-4.0.3.jar
-smack-tcp-4.0.3.jar
-xlightweb2.5.jar
-xpp3-1.1.3.3.jar
-xSocket-2.4.6.jar
Run Code Online (Sandbox Code Playgroud)
Using above library I am able to Connect with ejabberd and able to login with my login id and password but after some time of logging in connection gets close automatically and a am getting below stack trace
Sep 16, 2014 4:36:01 PM org.jivesoftware.smack.XMPPConnection …Run Code Online (Sandbox Code Playgroud) 嗨,我对实现chatManagerListener接口内部的逻辑感到困惑Service.以下是我的服务代码:
public class MyService3 extends Service {
ChatManager chatManager;
ChatManagerListener chatManagerListener;
AbstractXMPPConnection abstractXMPPConnection;
MyXmpp2 myXmpp2;
public MyService3() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("Myservice3:","Started");
abstractXMPPConnection = myXmpp2.getConnection();
abstractXMPPConnection.addConnectionListener(new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {
Log.d("XMPPConnection:","connected");
}
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
Log.d("XMPPConnection:","authenticated");
//Once authenticated start listening for messages
}
@Override
public void connectionClosed() {
Log.d("XMPPConnection:","connectionClosed");
}
@Override
public void connectionClosedOnError(Exception e) {
Log.d("XMPPConnection:","connectionClosedOnError");
}
@Override …Run Code Online (Sandbox Code Playgroud)