Raf*_*esp 2 google-app-engine xmpp
我想我做错了什么.我想向我的GTalk id发送XMPP消息,但我不希望GTalk应用程序收到消息,所以我正在更改收件人JID的资源.
我的问题是GTalk正在接收所有消息,尽管它们有不同的资源.
我的代码:
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws IOException {
// Parse incoming message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message msg = xmpp.parseMessage(req);
JID jid = msg.getFromJid();
String body = msg.getBody();
String jidID = jid.getId().split("/")[0];
JID jid2 = new JID(jidID+"/myownresource453242352");
String response = jid2.getId() + " " + body;
// Send out response
msg = new MessageBuilder().withRecipientJids(jid2).withBody(response).build();
xmpp.sendMessage(msg);
}
Run Code Online (Sandbox Code Playgroud)
输出:
Rafa Espillaque,18:33 - 你不应该回应!
prueba-gae-gdx@appspot.com,18:33 - rafaespillaque@gmail.com/myownresource453242352您不应该回复!
怎么了?
更新:
现在我从aSmack客户端向myapp@appspot.com/bot发送消息,它正在我的客户端向我重新发送消息.
问题是GTalk for Gmail和GTalk for Android正在注册所有已发送的邮件,但他们没有收到应用程序响应.其他客户端不显示我不与他们一起发送的消息.
我可以隐藏我的邮件到Gmail和Android吗?
我的代码:
服务器
public void doPost(HttpServletRequest req,
HttpServletResponse resp) throws IOException {
LOG.setLevel(Level.INFO);
// Parse incoming message
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message msg = xmpp.parseMessage(req);
LOG.info(msg.getStanza());
JID jid = msg.getFromJid();
String body = msg.getBody();
String response = "FullID: "+jid.getId()+" El mensaje recibido es: "+body;
// Send out response
msg = new MessageBuilder().
withRecipientJids(jid)
.withMessageType(MessageType.NORMAL)
.withBody(response)
.build();
xmpp.sendMessage(msg);
Run Code Online (Sandbox Code Playgroud)
}
客户:
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connectionConfiguration);
try {
Log.i("TAG","Trying to connect");
connection.connect();
Log.i("TAG","Connected");
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
Log.i("TAG","Trying to Log In");
connection.login("rafaespillaque@gmail.com",mypass, mires");
Log.i("TAG","Logged In");
} catch (XMPPException e) {
e.printStackTrace();
Log.i("TAG","Problem connecting or logging in");
}
//Creating chat object for processing friend chat
Chat chat = connection.getChatManager().createChat(Server, new MessageListener() {
//Overriding process message function of MessageListener Interface which will be
//called whenever a message is received
@Override
public void processMessage(Chat c, Message m) {
//Displaying message sent by friend
//System.out.println(friendId+ " : " + m.getBody());
Log.i("TAG", m.getBody());
message = m.getBody();
}
});
try {
Message out = new Message();
out.setBody("Definitivo22222222");
out.setType(Type.normal);
chat.sendMessage(out);
Log.i("TAG", "Mensaje enviado");
} catch (XMPPException e) {
Log.i("TAG", "No se envió el mensaje");
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
最后一件事:我在AppEngine Logs中看到Stanza从aSmack收到的不是普通类型而是聊天类型.
谢谢你的帮助!!
最后一件事:您可以通过从任何客户端和Gmail同时连接并与客户端进行通信来测试Gmail正在执行的操作.Gmail正在接收您的邮件.
再次感谢.
另一件事:我的目标是使用XMPP通过他们的Gmail帐户与游戏的2个客户进行通信.你知道另一种选择吗?
| 归档时间: |
|
| 查看次数: |
2389 次 |
| 最近记录: |