DEV Community

Cover image for How Chat Apps Know You’re Typing?
WattaDumb Explains
WattaDumb Explains

Posted on

How Chat Apps Know You’re Typing?

Sam sends Alex a message: “Coffee at five?”

A second later, three dots appear. Alex hasn’t sent a reply yet, so how does Sam’s phone know he’s typing?

An open connection

A chat app can use a WebSocket to keep a connection open between your device and a messaging server. Think of it like staying on a phone call. Either side can speak whenever it has something to say.

When Sam hits Send, his app sends the message to the server. If Alex is online, the server can forward it through Alex’s open connection, and his app displays the message.

The three dots are an update of their own

When Alex starts typing, his app sends a small update to the server. The update tells the server that Alex is typing. The server forwards it to Sam’s app, which shows the three dots.

The typing update doesn’t need to include the letters Alex has entered. If he changes his mind and deletes what he wrote, Sam may have seen the dots without ever receiving a reply.

In this case, Alex does reply: “Make it five thirty.” That’s a separate message, sent when he taps Send.

Watch it happen

In Episode 3 of Behind the Click, I animated the conversation so you can follow the original message, the typing update, and Alex’s reply as they travel between the two phones.

Top comments (0)