xSend Logo xSend

Serverless Chemistry: Unveiling xSend's Browser-to-Browser P2P Transfers

Discover how we leverage WebRTC and signaling servers to achieve high-speed, end-to-end encrypted file transfers strictly between web browsers—no installation required.

In the modern cloud era, most file-sharing utilities follow a straightforward, yet inefficient path: Device A uploads the file to a central server, and Device B downloads it. This middleman approach has three fatal flaws: bandwidth throttling, severe privacy risks, and skyrocketing server maintenance costs.

The core architectural philosophy of xSend is precisely the opposite: whenever network conditions allow, establish a direct, peer-to-peer (P2P) connection.

With our native desktop client, we wield full OS privileges, enabling us to forge high-speed conduits via raw TCP or QUIC. However, a major question arises: Can we achieve this same magic using a pure web browser, without asking users to install anything?

The answer is overwhelmingly yes. In this engineering deep-dive, we’ll peel back the layers of how xSend utilizes WebRTC to shatter browser sandbox isolation, allowing two total strangers on the internet to securely shake hands.

1. Finding Each Other: The Signaling Server

For security reasons, browsers cannot arbitrarily broadcast UDP packets across your local network to discover nearby peers (unlike native mDNS implementations).

Therefore, we introduce an ultra-lightweight matchmaker: The Signaling Server.

Within xSend’s architecture, this job is delegated to a Cloudflare Worker node (SignalAutoDO). When two users enter the same 6-digit code (or scan a QR code):

  1. Both browsers instantly initiate a WebSocket connection to the same signaling rendezvous point.
  2. The server logically groups them into a restricted “room.”
  3. Both peers exchange SDP (Session Description Protocol, detailing supported codecs) and ICE Candidates (Interactive Connectivity Establishment, listing their local and public IP addresses).

Privacy Guarantee: The signaling server acts merely as a bulletin board to swap these connection metadata strings. It never touches, sees, or intercepts the actual file content.

2. Piercing the Firewall: ICE and UDP Hole Punching

Armed with the other party’s IP addresses, the browsers attempt to connect. Since IPv4 depletion means most users sit behind NAT (Network Address Translation) routers, this is harder than it sounds.

Local Network Detection (LAN)

If both browsers happen to be on the same Wi-Fi network, the exchanged ICE candidates will feature internal IPs (like 192.168.1.10). The browser’s underlying networking engine will prioritize these local routes. Once connected, the file data never leaves your router, ensuring immense speeds and flawless security.

Wide Area Network: STUN (WAN Hole Punching)

If the devices are on different networks (e.g., one on home Wi-Fi, the other on cellular 5G):

  • The browser pings our STUN Server, functionally asking, “What does my public IP address look like?”
  • The STUN server replies with the public IP and external mapped port.
  • Both browsers then aggressively send UDP packets addressed to each other’s wide-open port. Unless blocked by a strict Symmetric NAT configuration, these packets cross paths—a process known as UDP Hole Punching. A direct WAN P2P tunnel is born.

3. The Secure Highway: SCTP over DTLS

Once the tunnel is established, how is the data sent?

By default, WebRTC serves UDP for audio/video calling, where dropping a video frame is fine, but dropping a file chunk is catastrophic. To ensure integrity, xSend utilizes RTCDataChannel.

This exposes a robust transport protocol known as SCTP (Stream Control Transmission Protocol), which provides TCP-like ordered and reliable delivery over UDP packets.

Crucially, RTCDataChannel enforces mandatory DTLS (Datagram Transport Layer Security). Every single byte of your file is symmetrically encrypted with keys derived from a rigorous asymmetric handshake. If your traffic were somehow hijacked en route, the attacker would capture nothing but cryptographic noise.

4. The Failsafe: TURN Relaying

In hostile networking environments (strict corporate firewalls or complex mobile carrier symmetric NATs), UDP hole punching is doomed to fail. We cannot abandon the user, so xSend gracefully downgrades to a TURN relay (Traversal Using Relays around NAT).

  • The browsers negotiate a connection through one of our globally distributed Cloudflare edge nodes serving as a TURN relay.
  • Security remains totally uncompromised. Because the underlying DTLS end-to-end encryption stays intact during the relay, the Cloudflare server acts as a blind delivery service. It cannot decrypt the file payload.

In our latest v0.2.0 modernization, we scrapped the legacy Base64 JSON approach traversing TURN. We introduced a highly-optimized Binary Chunk Framing protocol, slashing transport overhead by ~33%.

Epilogue: The Edges of Browser Performance

Engineering honesty requires us to admit that browser P2P isn’t without its costs. JavaScript memory copying, Blob-to-ArrayBuffer conversions, and sandbox overhead mean that even on a gigabit LAN, an optimized browser can typically only push 30-50MB/s before CPU bottlenecks appear.

If you regularly transfer multi-hundred-gigabyte folders and demand maximum hardware saturation, our Native Desktop Daemon effortlessly overcomes these limits—by speaking directly to the OS network stack.

But until you need that industrial-grade bandwidth, enjoy the sheer technological magic of tapping a link and teleporting files directly through your browser.