Reputation: 31
I was analyzing chat application like telegram or whatsapp. as you know they are using a tcp connection to server. the big problem of tcp connection is that when there is any issue in internet connection the xmpp client will be disconnected from server without telling server that i am disconnected and tcp connection will be open from server and message will be lost.
So one way for client and server to understand connection is lost is using ping .that is we set a time for server and client to ping each other and if connection is lost retry to connect. and again main problem of this solution is that it drains a lot of battery charge if for example we set client to ping each 10 second and if we set server to ping user each 40 second it will put a lot of load on server when we are dealing with lots of user.
But telegram and whatsapp doesn't have this problem because they will understand the tcp connection is lost up to 30 second and telegram is even faster and it will know in 4 or 5 second.
My problem is that i dont think whatsapp or telegram are using ping system actually pinging server each 10 second because it will drains battery.
What is your idea ? are they using ping system or they have found any solution for it.
I would be very thankful if anybody explain me how they are doing that
Upvotes: 2
Views: 2463
Reputation: 9055
You need to have some keepalive mechanism and have your server detect connection loss by missed keepalive. Otherwise, depending on the server configuration it can take a very long time to detect connection loss at TCP level.
Upvotes: 1
Reputation: 329
TCP itself has a way of detecting connection loss, so you don't need to ping at all. However, you can make a higher level heartbeat signal, in case the usual TCP way isn't fast enough.
Upvotes: 3