read incoming Message packets in pubsub using smack

。_饼干妹妹 提交于 2019-12-13 11:52:29

问题


i am trying to implement pubsub using openfire server and asmack library. i have configured my node in such a way that subscribers has to take the approval of publishers

now i am trying to read the Message packet using following code but i am not getting any packet. i want to read Message packet because i want to know whenever the subscribers send the request to publishers to get subscribe.

PacketTypeFilter filter = new  PacketTypeFilter(org.jivesoftware.smack.packet.Message.class);

    PacketListener myListener = new PacketListener(){

        @Override
        public void processPacket(Packet packet) {
            // TODO Auto-generated method stub

            Log.d("PACKET" , "READ");

            if(packet instanceof org.jivesoftware.smack.packet.Message){

                    org.jivesoftware.smack.packet.Message msg = (org.jivesoftware.smack.packet.Message) packet;

            Log.d("MY MESSAGE" , msg.toXML()+ "");


                    }
                }

            };

    cxmpp.addPacketListener(myListener, filter);

All i want is to read the incoming Message Packets


回答1:


If you have all the configuration bits and your pubsub component correctly working, then for getting a normal message you would do something like:

ConnectionConfiguration config = new ConnectionConfiguration("ADDRESS",PORT); // service name, also known as XMPP domain of the target server. 
config.setServiceName(this.pubsubServiceAddress);
connection = new XMPPConnection(config);
connection.connect();

PacketFilter filter = new MessageTypeFilter(Message.Type.normal); 

connection.addPacketListener(new PacketListener() { 
    public void processPacket(Packet packet) {
    Message mes = (Message)packet;
        // do your stuff here
    }
}, filter);


来源:https://stackoverflow.com/questions/13777234/read-incoming-message-packets-in-pubsub-using-smack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!