Android Question Detect sender & recipient typing in messaging app

swabygw

Active Member
Licensed User
Longtime User
I'm creating a messaging app and I'd like to implement the feature of showing when the other person, on the other side of a message, is typing. Because I'm used to using databases, my first inclination was to use a database on a web server to do it: the idea being that when UserA is typing, the database is updated, via web services, in the edittext_TextChanged event (given some unique criteria). UserB, whose app is polling the database, can, also via web services, view the timings entered from UserA and show, or not show, that typing is occurring.

This approach works (I've tried it!), however, the latency is limited to two web service calls. So, if, for example, UserA takes 25 seconds for the INSERT, via web service, to complete...and it takes UserB 20 seconds to retrieve the row, via web service...the answer that UserB sees is 45 seconds behind the actual keypress.

I'm not convinced that a database in between the users is the best method (i.e., lowest latency), and I was wondering if anyone knows of a better method to do this. Thoughts?
 

swabygw

Active Member
Licensed User
Longtime User
That sounds good. I was thinking that maybe there is a way to create a "channel" between the phones directly, like a socket-to-socket connection, to eliminate or minimize the need to do a read/write at an intermediary point. But, I'll look into the B4J server...I hadn't thought of that - thanks.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
since most data plans, the IP address can change within a fraction of a second, (i have encountered this), and some APNs block all incoming ports, its much easier for the two devices to connect to a central socket server and create a "nexus" between the two through the 3rd party relay. Sorta how Teamviewer works without needing to open ports.

All traffic coming from socket A gets forwarded to socket B, and vice versa. Some sort of routing protocol would need implemented if your using more than 2 devices at a time.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Yes - I was thinking of something along those lines whereby the central server sets up a connection for directing traffic between the two parties, but doesn't actually have to store any data.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…