KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Note: UDP Sockets: Peer-to-Peer Communication
PRODUCT: 4D | VERSION: 20 R10 | PLATFORM: Mac & Win
Published On: December 22, 2025

This technical note details a comprehensive implementation of a peer-to-peer discovery mechanism, centered on the PeerDiscovery class and supporting methods for local private networks. The class utilizes 4D's UDPSocket and UDPEvent classes to handle broadcast announcements, probe responses, and event-driven data reception, maintaining a shared collection of peers with automatic expiration via TTL pruning. Key components include lifecycle management for initialization and shutdown, peer addition/refresh logic with shared object safety. Accompanied by the RunPeerDiscovery worker for continuous operation and Util_formatLastSeen for timestamp formatting, the system enables any 4D application to detect and track instances on the same network without servers or dependencies.

Download Complete Tech Note: Tech Note Document