Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lossing messages due to connection loss through openfire

Turning off internet on mobile device directly causes problems in my chat application. Messages are not stored in openfire offline table as Openfire still shows me online on abrupt disconnection from the server. when a relogin attempt is made the messages that were sent in that period are lost.

I am working on a chat application,after login to openfire I am able to chat and other users can see me online but the problem is if one user losses the connection like WIFI off,In such situation Openfire is not showing my status as offline and it still shows Online which results in message packet loss.

Please provide me the solution I am unable to resolve it.

On a sidenote how whatsapp and other apps send messages. Do they use message storage strategy on server and acknowledgement or am I missing something here.

like image 869
user2384410 Avatar asked Jul 02 '14 15:07

user2384410


1 Answers

Both client and Server needs to acknowledge that messages were sent & delivered, say for instance you send a message to someone else, what you can do here is that you save this message on your server, from server this message will be sent to receiver and wait for an acknowledgement by the receiver that the message was delivered, once you get acknowledgement - delete the message from the server.

How whatsapp do it? I found this answer by Michael Donohue on Quora

Whatsapp works on store and forward, The WhatsApp client will store any message you send, and keep trying to send it to the WhatsApp servers. When a WhatsApp mobile app connects to the chat servers, the store-and-forward process occurs in both directions. The client sends any pending messages in it's mesage store to the server, while the server sends all the accumulated messages destined for that client to the client. This process is done on an acknowlegement basis. This means messages are sent repeatedly until the other side acknowledges receipt of the message. server drops messages once they are acknowledged - there is no long term storage. Whereas the client will update the UI to double-check status once the ack arrives, but will keep the message.

like image 100
Yauraw Gadav Avatar answered Nov 10 '22 20:11

Yauraw Gadav