2016-04-12 8 views
0

私はEjabberdをXMPPサーバとして使用し、smack APIでxmppクライアントを作成しています。Smack APIクライアントからejabberdのメッセージで追加のパラメータを送信したい

私のコードは以下の通りです:このコードにより、

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("[email protected]","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("[email protected]").sendMessage(message); 
        message.setBody(stanza); 
        System.out.println("Message Sent"); 

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

    } 

私はXMPPスタンザにタイプを追加することですが、私は私がメッセージとともに追加のパラメータを送信するために助けが必要way.Soことは好ましくないと思います。 私が解決策を得れば、これは高く評価されます。 ありがとうございます!

答えて

2

あなたはthat-

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

like-それを得ることができます
関連する問題