WhatsApp获取接收方IP地址机制及通话流程技术咨询
WhatsApp Technical Mechanics Explained
Great questions about how WhatsApp handles message delivery and calls—let’s break down each one with clear, actionable details:
1. Delivering Messages to Offline Users (A → Offline B, Then B Comes Online)
When user B is offline, WhatsApp doesn’t immediately "track down" B’s IP address—instead, it uses a combination of server-side storage and client-initiated connections to get messages delivered:
- Step 1: Message Storing When A sends a message to offline B, the end-to-end encrypted message is first sent to WhatsApp’s cloud storage servers. The server tags the message with B’s account ID and marks it as "pending delivery."
- Step 2: B Initiates Reconnection When B’s device comes back online, it actively establishes a TLS-secured TCP connection (usually over port 443) to WhatsApp’s core servers. During this connection handshake, the server automatically gets B’s public IP address (and port, if behind NAT) from the incoming TCP request.
- Step 3: Message Push WhatsApp’s servers detect B’s online status, check for pending messages linked to B’s account, and push the encrypted message through the already-established TCP connection to B’s client.
- Bonus: Multi-Device Handling If B uses multiple devices (e.g., phone + desktop), the server pushes the message to all online devices until at least one confirms receipt, then marks the message as delivered.
2. WhatsApp Call Flow (Initiating a Call to C)
WhatsApp calls rely on a mix of server-side routing and peer-to-peer (P2P) connections, with end-to-end encryption at every stage:
- Step 1: Initial Call Request When you initiate a call to C, your WhatsApp client encrypts the call request (including device ID, call type: voice/video) and sends it to WhatsApp’s dedicated call routing servers.
- Step 2: Check Recipient Status The servers first verify if C is online. If C is offline, you’ll get an "unavailable" notification, and the call terminates. If C is online, the server forwards the encrypted call request to C’s client.
- Step 3: Ringing & Answer C’s client displays the call alert and sends a "ringing" status back to the servers, which relays this to you. When C answers, their client generates a session key (using the Signal Protocol’s Double Ratchet algorithm) and sends the public key portion to the servers, which forwards it to your client.
- Step 4: P2P or Relay Connection
- First, both clients attempt a direct UDP P2P connection: they exchange public IP/port details (via the server) and use UDP hole punching to bypass NAT if needed.
- If P2P fails (e.g., strict NAT restrictions), WhatsApp’s TURN (Traversal Using Relays around NAT) servers act as a middleman, relaying encrypted call traffic between you and C. The servers never decrypt the traffic—they only forward it.
- Step 5: Call Termination When either party hangs up, their client sends a termination signal to the servers, which notifies the other client, and all connections are closed.
内容的提问来源于stack exchange,提问作者Murad Zulfugarov




