Listen to the episode "How to Build Peer-to-Peer Mobile and Desktop Apps with Socket Supply" on JSJ 588 podcast.
Guest: The author of "You Don't Know JS" and currently working at Socket Supply.
Socket Supply is a tool that aims to support different platforms with one code base, solving the problem of multi-platform development. It allows building desktop and mobile applications using web technologies. Similar solutions have been available for over a decade, such as PhoneGap, Apache Cordova, NativeScript, Ionic, React Native, Tauri, and Electron. These frameworks wrap web applications to run on different native platforms. Socket Supply is also part of this trend, providing an open-source runtime that wraps a web app like a PWA (Progressive Web App) to make it available on various platforms.
Capacitor, which is built on Cordova, is a codebase that is over 15 years old and was originally designed for mobile devices. While it does use Electron for desktop, it adds complexity to the project. Socket Supply, on the other hand, is built from scratch for mobile, desktop, headless, and web, with a focus on using existing web standards like CSP (Content Security Policy) to sandbox native APIs and implement modern networking features like peer-to-peer communication.
Socket Supply stands out with its unique features:
- It is a new solution that avoids the historical baggage of older frameworks.
- It does not require a separate backend process and can be run within a web view, resulting in a much smaller package size compared to Electron or Tauri.
- The runtime provides complete access to file systems, Bluetooth, and networking. However, complete network access is not allowed within a browser due to API restrictions.
- Socket Supply has designed a serverless peer-to-peer protocol that allows communication without the need for a central server.
The game-changing aspect of Socket Supply is that it eliminates the need for a backend, including databases and storage, which are typically required by most applications.
As for the business model, Socket Supply is free for infrastructure usage. However, customers can pay for additional professional tools like analytics and performance analysis. The goal is to provide more professional and convenient features, such as one-click deployment to app stores.
Socket Supply targets all types of companies, both large and small. It is possible to use Socket Supply alongside existing cloud services, which can lead to significant cost reduction. However, migrating from cloud services to a peer-to-peer architecture takes time and requires careful planning and parallel operation.
Socket Supply does not use Web3 technologies and can be considered a pre-Web3 solution or Web 2.5.
The technology behind Socket Supply does not rely on WebSocket, WebRTC, or WebStream. These technologies do not meet the requirements for building a peer-to-peer network, so Socket Supply uses a UDP-based approach.
IPv6 is not the savior for Socket Supply as it has its own challenges, especially with NAT traversal. Socket Supply has a strong focus on the "local first" concept and has formed a community around it at localfirstweb.dev.
The host asks about the technical and use case explanation of a UDP-based peer-to-peer network.
A UDP-based peer-to-peer network is a decentralized network architecture where communication between nodes is done using the UDP protocol. Compared to traditional TCP-based peer-to-peer networks, UDP is more suitable for applications that require real-time communication and have low bandwidth requirements.
Technically, UDP-based peer-to-peer networks often use NAT traversal techniques to overcome the limitations imposed by Network Address Translation (NAT) on P2P communication. NAT traversal can be achieved through the use of relay servers or techniques like UDP hole punching, allowing nodes in different private networks to communicate directly without relying on public IP addresses.
UDP-based peer-to-peer networks are suitable for various use cases, including:
- Real-time communication: UDP's low latency and high real-time capabilities make it suitable for applications like real-time audio/video calls and online gaming that require fast data transmission.
- Large-scale file sharing: P2P networks can divide files into smaller chunks and distribute them among multiple nodes, improving file transfer speed and reliability.
- Media streaming: UDP-based P2P networks can be used for streaming media, such as live streaming and video-on-demand, by leveraging multiple nodes to provide media data and reduce server load.
- Decentralized applications: UDP-based P2P networks can be used to build decentralized applications, such as blockchain and file storage, enabling direct communication and data sharing between nodes.
It's important to note that UDP-based P2P networks may face challenges such as packet loss and out-of-order delivery due to the nature of the UDP protocol. Therefore, designing and implementing such networks requires balancing data reliability and transmission efficiency.