Ashish Bhatia
Ashish Bhatia

Reputation: 51

how to add additional data in message asmack/smack?

I am sending a message with (a)Smack and Openfire server. I am successfully able to send message with the message body. Now i need to send some additional data with the message. I don't want to append the string to the data and then process it after receiving. Is there any other approach? or with extensions?

Upvotes: 0

Views: 419

Answers (2)

Manish Modgill
Manish Modgill

Reputation: 11

You can use setProperty and getProperty method.

At sending end:

Message msg=new Message("jid", Message.Type.chat);
msg.setProperty("key", "value");
connection.sendMessage(msg);

At receiving end:

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
    packetListner=new PacketListener() {
        public void processPacket(Packet packet) {

            Message message = (Message) packet;
            String myData=message.getProperty("key").toString();
        }
    };
    connection.addPacketListener(packetListner, filter);

Upvotes: 1

Flow
Flow

Reputation: 24053

Use a custom PacketExtension.

Upvotes: 1

Related Questions