Google Talk用不同的jid资源接收消息 [英] Google Talk receiving messages with different jid resource

查看:100
本文介绍了Google Talk用不同的jid资源接收消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我做错了什么。
我想发送XMPP消息给我的GTalk ID,但我不希望GTalk应用程序收到消息,因此我正在更改收件人JID的资源。



我的问题是GTalk正在接收所有消息,尽管它们有不同的资源。



我的代码:

  public void doPost(HttpServletRequest req,
HttpServletResponse resp)抛出IOException {

//解析传入消息
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
消息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;

//发出响应
msg = new MessageBuilder()。withRecipientJids(jid2).withBody(response).build();
xmpp.sendMessage(msg);




输出:


  • 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吗?



我的代码:

SERVER

  public void doPost(HttpServletRequest req,
HttpServletResponse resp)throws IOException {
LOG.setLevel(Level.INFO);
//解析传入消息
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
消息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;

//发出响应
msg = new MessageBuilder()。
withRecipientJids(jid)
.withMessageType(MessageType.NORMAL)
.withBody(response)
.build();
xmpp.sendMessage(msg);

}



客户:

  ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(talk.google.com,5222,gmail.com); 
XMPPConnection connection = new XMPPConnection(connectionConfiguration);
尝试{
Log.i(TAG,尝试连接);
connection.connect();
Log.i(TAG,Connected);
SASLAuthentication.supportSASLMechanism(PLAIN,0);
Log.i(TAG,尝试登录);
link.login(rafaespillaque@gmail.com,mypass,mires);
Log.i(TAG,Logged In);
} catch(XMPPException e) {
e.printStackTrace();
Log.i(TAG,连接或登录问题);
}
//创建用于处理朋友聊天的聊天对象
Chat chat = connection.getChatManager()。createChat(Server,new MessageListener(){
//重写MessageListener接口的过程消息函数,它将是
//每当接收到消息时调用
@Override
public void processMessage(Chat c,Message m){
//显示朋友发送的消息
//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 seenvióel mensaje);
e.printStackTrace();
}

最后一件事:我在AppEngine日志中看到Stanza从aSmack是不正常的类型,但聊天类型。



感谢您的帮助!!



最后一件事:您可以通过从任何客户端和Gmail同时连接并与客户通话来测试Gmail的功能。 Gmail收到您的邮件。



再次感谢。

另一件事:
我的goalis使用XMPP通过他们的Gmail账户与2个游戏客户进行交流。你知道一个替代方案吗?

RFC 6120,第10.5.4节


如果'to '属性的形式是
localpart @ domainpart / resourcepart ,并且用户存在,但是
没有与完整JID完全匹配的连接资源, stanza
应该按照Section localpart @ domainpart .ietf.org / html / rfc6120#section-10.5.3.2> 10.5.3.2


如果您发送对于无效的资源,服务器会将它视为已将其发送到裸露的JID。在GoogleTalk上,这将适用于所有非负面的优先资源。


I think I'm doing something wrong. I want to send a XMPP message to my GTalk id but I don't want that the GTalk app receives the message so I'm changing the resource of the recipient JID.

My problem is that GTalk is receiving all the messages although thay have different resource.

My code:

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);

}

The output:

  • Rafa Espillaque, 18:33 - You shouldn't respond!

  • prueba-gae-gdx@appspot.com, 18:33 - rafaespillaque@gmail.com/myownresource453242352 You shouldn't respond!

What's wrong?

UPDATE:

Now I'm sending messages to myapp@appspot.com/bot from an aSmack client and it is resending the message to me at my client.

The problem is GTalk for Gmail and GTalk for Android is registering all sent messages but they don't receive the app responses. Other clients don't show the messages I don't sent with them.

Will I be able to hide my messages to Gmail and Android?

My code:

SERVER

  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);

}

CLIENT:

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();
                    }

Last thing: I've seen in AppEngine Logs that the Stanza received from aSmack isn't of normal type but chat type.

Thanks for helping!!

Last-last thing: You can test what Gmail is doing by connecting from any client and Gmail at same time and talking from the client. Gmail is receiving your messages.

Thanks again.

Another thing: My goalis use XMPP to communicate 2 clients of a game with their gmail account. Do you know an alternative?

解决方案

See RFC 6120, section 10.5.4:

If the JID contained in the 'to' attribute is of the form localpart@domainpart/resourcepart and the user exists but there is no connected resource that exactly matches the full JID, the stanza SHOULD be processed as if the JID were of the form localpart@domainpart as described under Section 10.5.3.2.

If you send to an invalid resource, the server treats it as if you had sent it to the bare JID. On GoogleTalk, this goes to all non-negative priority resources.

这篇关于Google Talk用不同的jid资源接收消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆