I have been trying to create an android chat app using smack 4.1. Message sending and receiving is working fine, but the problem is same message is getting several times with in the mXmppConnection.addAsyncStanzaListener.I don't know if i have missed to add something to the connection.
This is my connection class:
XMPPTCPConnectionConfiguration.Builder configBuilder = new XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(mUser, "password@123");
configBuilder.setPort(5555);
configBuilder.setServiceName("tvm.myname.com");
configBuilder.setDebuggerEnabled(true); configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
try
{
XMPPTCPConnection mConnection = new XMPPTCPConnection(configBuilder.build());
mConnection.connect();
mConnection.login();
}
catch (SmackException e)
{
}
mXmppConnection.addAsyncStanzaListener(new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
Message message = (Message)packet;
Log.i("XMPPClient", "****** message " + message);
// code for handling message
} `enter code here`
},null);
The real problem is i am getting the message several times..the value of message is printing in the logs several time. Please help me....
FINALLY GOT SOLUTION
The issue is not with the client but due to careless coding. I have been assigning single instance of connection object to a class variable and listener is adding to these reference object every time. So that leads to calling listener multiple times....The fix is done by adding listener to the singleton connection object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With