我在谷歌搜索了很多,并在这里找到XMPP客户端的最佳功能API.
我发现了以下两点:
asmack :. http://code.google.com/p/asmack/
patched smack:http://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/
我无法在互联网上找到这两个API的比较,所以也许你可以帮助我选择哪一个.
在补丁的原始文章中,他告知TLS不起作用(很好,我不应该使用它)我消耗其余的工作.另一方面,asmack非常受欢迎,但当我在网上阅读时,似乎它有点多了?
你建议我选择什么?
谢谢!
我正在为一家公司工作,该公司正在使用Google Chatback(与我公司案例中的支持员工进行匿名聊天)作为主要的聊天服务提供商.此服务使用XMPP(以前称为Jabber)协议来发送和接收消息.
我们公司有十个支持员工帐户,可以通过我们在我们网站上使用的聊天服务访问它们.员工同时使用Mac OSX和Windows,以及不同操作系统上的不同客户端.聊天也可以通过Android和iOS上的原生应用程序获得.
我们需要一种用于记录聊天会话的服务,我们一直在寻找专有的解决方案,但这些在移动平台上是不受支持的,而且这基本上就是交易破解者.
我决定的解决方案是在消息链中引入另一个链接,记录所有消息.这个想法是服务器通过这个代理发送,根据它的聊天会话记录消息,然后以适当的方式保存这些日志.目前,他们将所有日志存储在Dropbox文件夹中,这是一个容易出错的活动.
理论上,这将允许我们的支持者使用他们选择的任何操作系统/客户端,并且日志将最终在同一个地方.
在使用Smack API进行了一些测试之后,我得出结论,我的XMPP客户端(Android和Windows上的Trillian)都回复了它上次收到消息的资源.这实际上意味着我实现的非常简单的聊天记录器被忽略了.
使用下面的代码与另一个并行运行的客户端进行了测试.只有一个客户端收到该消息.
ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "googlemail.com");
config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
Presence presence = new Presence(Presence.Type.unavailable);
connection.login("android_client_username", "android_client_pass");
Message message = new Message("my_test_email@gmail.com");
message.setBody("Hello World!");
connection.sendPacket(message);
connection.sendPacket(presence);
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
System.out.println(message.getBody());
}
}
}, new MessageTypeFilter(Message.Type.chat));
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) 我是使用smack库和制作一个聊天应用程序的新手.我已经做了很多工作,在这一步我想问两个问题.
当我添加一个朋友时,朋友已添加到我的列表中,但没有任何通知发送给我已添加的FRIEND,如何实现相同.我在下面添加了代码.
我要问的第二件事是,我如何检查我要添加的用户是否是应用程序的一部分或成员(意味着它是否在服务器上).因此,不应将未注册到应用程序的用户添加到好友列表中.
这是代码
public static boolean addFriend(String jid) {
String nickname = null;
nickname = StringUtils.parseBareAddress(jid);
RosterEntry entry4 = roster.getEntry("samsad");
if (!roster.contains(jid)) {
try {
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo(jid);
connection.sendPacket(subscribe);
roster.createEntry(jid, nickname, null);
// Send a roster entry (any) to user2
RosterExchangeManager REM = new RosterExchangeManager(connection);
REM.send(entry4, jid);
return true;
} catch (XMPPException e) {
System.err.println("Error in adding friend");
return false;
}
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
在后台运行服务的名册交换经理
/**Remotr Exchange Manager*/
RosterExchangeManager rem = new …Run Code Online (Sandbox Code Playgroud) 嗨,我正在研究ejabberd,并且对这项技术还很陌生。
我正在尝试使用以下代码在我的ejabberd服务器上添加用户:
try {
conf.setSASLAuthenticationEnabled(true);
connection.connect();
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
Log.i("XMPPClient", "Connected to "
+connection.getHost());
createUser("tester","testerpass");
}
} catch (XMPPException e1) {
Log.e("XMPPClient", e1.toString());
xmppClient.setConnection(null);
}
public void createUser(String user, String pass) {
try {
//Admin login
connection.login(user, pass);
} catch (XMPPException e) {
e.printStackTrace();
}
Log.i("connection.isAuthenticated() : ",""+connection.isAuthenticated() );
if (connection.isAuthenticated()) {
AccountManager manager = connection.getAccountManager();
try {
manager.createAccount(user, pass);
} catch (XMPPException e) {
Log.w("[create_user] Cannot create new user: XMPP Exception.", "0");
e.printStackTrace();
} catch (IllegalStateException e) {
Log.w("[create_user] Cannot create …Run Code Online (Sandbox Code Playgroud) 我在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)
关于我做错的任何建议?
我想在我的XMPP聊天消息中添加自定义属性(缺口),如下例所示
<message from='*' to='*' id='123' nick='KASHIF' type='chat'><body>hello</body></message>
Run Code Online (Sandbox Code Playgroud)
我知道,XMPP 并不推荐它,但这是我的要求,因为这个属性(缺口)已经在我正在使用的iOS版本的应用程序中实现.
实施嫌API现在试图让喜欢的用户是否是聊天状态Composing,Paused等等.我迄今所做
public class IncomingChatListener implements ChatMessageListener, ChatStateListener {
@Override
public void stateChanged(Chat chat, ChatState state) {
Log.d("-----","into chat state");
if (ChatState.composing.equals(state)) {
Log.d("Chat State",chat.getParticipant() + " is typing..");
} else if (ChatState.gone.equals(state)) {
Log.d("Chat State",chat.getParticipant() + " has left the conversation.");
} else {
Log.d("Chat State",chat.getParticipant() + ": " + state.name());
}
}
public void processMessage(Chat chat, Message message) {
.......
......
}
Run Code Online (Sandbox Code Playgroud)
当用户输入时,我发送的状态如下:
ChatStateManager.getInstance(connection).setCurrentState(ChatState.composing, myChat);
Run Code Online (Sandbox Code Playgroud)
问题是stateChanged函数永远不会被调用而是函数中收到了像编写等的chatStatus包processMessage.
我怎么能在stateChanged功能上收到它?
嗨,我对实现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)