我想在ejabberd中通过Smack API客户端发送带有消息的附加参数

时间:2016-04-12 09:38:05

标签: xmpp ejabberd

我使用Ejabberd作为XMPP服务器并在smack API中创建xmpp客户端。我想发送带有消息的附加参数。

我的代码如下:

public static void main(String[] args) throws SmackException,IOException,XMPPException {

         XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                  .setResource("Smack")
                  .setSecurityMode(SecurityMode.disabled)
                  .setServiceName("localhost")
                  .setHost("localhost")
                  .setPort(Integer.parseInt("5222"))
                  .build();
                AbstractXMPPConnection conn = new XMPPTCPConnection(config);
                try {                                           
                    conn.setPacketReplyTimeout(10000);
                    SASLAuthentication.unBlacklistSASLMechanism("PLAIN");
                    SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
                    SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");
                    //SASLAuthentication.
                    conn.connect();
                    conn.login("test1@localhost","123456");
                    System.out.println("login successfull");
                    Message message = new Message();
                    String stanza = "i am vip";                 
                    message.setBody(stanza);
                    stanza+= "<type>.jpg</type>";
                    ChatManager manager = ChatManager.getInstanceFor(conn);
                       manager.createChat("vipul@localhost").sendMessage(message);
                    message.setBody(stanza);
                    System.out.println("Message Sent");

                } catch (Exception e) {
                    e.printStackTrace();
                }

    }

通过这段代码,我能够在xmpp节中添加类型,但我认为这不是更好的方式。所以我需要帮助发送带消息的附加参数。 如果我得到解决方案,将不胜感激。 谢谢!!

1 个答案:

答案 0 :(得分:2)

您可以添加其他参数 -

Message message = new Message();
                    String stanza = "i am vip";                 
                    message.setBody(stanza);
 message.addBody("customtag","Custom tag value");
 message.addBody("customtag1","Custom tag value1");

你可以得到它 -

String customtageValue= message.getBody("customtag");

for more detail check this link