Students who use Apple's full range of services must have experienced seamless connection between multiple devices, such as sending photos and files through AirDrop, AirPlay TV screen projection, automatic sharing of hotspot passwords, Apple Watch unlocking Mac and iPhone, continuous camera/sketch/marking, etc. Their basic principle is to quickly synchronize data between devices logged in to the same iCloud via Wi-Fi or Bluetooth. The problem is that if devices in a local area network want to communicate, they need to know each other's IP address. Taking AirPlay screen casting as an example, the first step is that the terminal device such as the iPhone needs to find the target screen casting device (i.e. TV) in the local area network before the audio, video, picture or screen content can be projected to the TV. In most cases, the IP address of the device is obtained through the dynamically assigned DHCP protocol. So, how do devices discover each other? This is when the Bonjour protocol comes into play! What is the Bonjour protocol? Bonjour is a zero-configuration network protocol implemented by Apple. The word "Bonjour" comes from French and means "hello" or "good morning". The protocol is designed to simplify network configuration and allow devices to easily discover and communicate with each other in a local area network, just like people saying hello. With Bonjour, users do not need to manually configure IP addresses or device names. Devices or applications can automatically detect the required services or other interactive applications, achieving automatic connection, communication, and data exchange without user intervention. Figure 1 Interconnection of devices in a LAN How does the Bonjour protocol work? 1. Bonjour protocol basics Bonjour is mainly based on two standard network protocols: mDNS (multicast DNS) and DNS-SD (DNS Service Discovery), and is built and extended on the standard DNS framework. 1.1 mDNS protocol The mDNS protocol is based on UDP/IP and uses the multicast address 224.0.0.251 and port 5353 for communication. The mDNS protocol implements host name resolution within the LAN through multicast query and response without configuring a DNS server. The mDNS protocol packet format is consistent with the standard DNS protocol. While supporting standard DNS query record types, it also expands some of the concepts. Among them, resource records are used to exchange message content between hosts in a local area network and contain the following key fields: NAME: indicates the message content TYPE: indicates the type of message content Furthermore, according to the TYPE type, the following key DNS record formats can be defined: A record: the correspondence between the host name and IPv4 AAAA record: the correspondence between host name and IPv6 PTR record: records the correspondence between the service type and the service instance name, and is generally used to query and discover service instances SRV record: records the host name and port information of the service instance TXT record: provides additional descriptive text for the service, recorded in the format of "key = value", such as MAC address, device ID, etc. ANY record: any type, generally used in queries 1.2 DNS-SD Protocol The mDNS protocol defines the basic structure of messages and the message transmission process. On this basis, the DNS-SD protocol further defines specific elements such as service name, service instance name, domain name length/sequence, etc., uses three resource records, PTR, SRV and TXT, to fully describe a service, and specifies a simple service discovery and description method. The service name is usually composed of an underscore "_" and a protocol name, and "local" is used as a fixed identifier at the end of the domain name. The format is <service type>.<domain name>.local, such as: _printer._tcp.local, _airplay._tcp.local The service instance is identified by its instance name, in the format of <service instance>.<service type>.<domain name>, such as: PrintsAlot._printer._tcp.local MyMac._airplay._tcp.local The Bonjour protocol implements host name resolution and service registration and discovery within the local area network through the above two protocols, providing a foundation for zero-configuration networks. 2. Bonjour service discovery process To understand how Bonjour works, we only need to think about how the mDNS protocol and DNS-SD protocol mentioned above are combined to interact. The Bonjour protocol can be seen as an organic combination of mDNS and DNS-SD. Specifically, the DNS-SD protocol points to the service instance through the PTR record and provides the host name and port of the instance through the SRV record; after obtaining this information, it only needs to resolve the host name through mDNS to obtain the IP address, and then the mapping relationship from the service name to the IP address can be completed, thereby realizing end-to-end connection. It should be noted that these record information published and queried by DNS-SD are all transmitted based on the multicast group and port number defined by mDNS. Next, we will give a specific example to illustrate how the entire Bonjour service discovery process is completed. Suppose an iPad device in the local area network wants to publish a music sharing service, which mainly includes the following three steps: 2.1 Service Publication First, the device will randomly select an available link-local IP address, such as 192.168.1.23, and publish it to the LAN. Second, it will start the mDNS responder and request the host name my-ipad.local. After confirming that there is no conflict, it will use the host name. Then, the device will start the music sharing service on TCP port 1010. Finally, the music service will be published and the DNS record will be created through mDNS multicast: SRV record: The content is the service instance name "Xiao Li's music service._music._tcp.local." and points to the TCP service port 1010 on the host name my-ipad.local. PTR record: The content is the service name "_music._tcp.local." and points to the service instance name "Xiao Li's music service._music._tcp.local." TXT record: provides additional information about the device, such as the MAC address "MAC=D3:AA:E2:30:B0:E1" When other devices in the local area network receive these records, they will parse and cache them.
2.2 Service Discovery When a client application needs the music sharing service, it constructs a service query message of the _music._tcp type and multicasts the query request to the entire LAN through mDNS. After receiving the query request, the device that can provide the service responds with a PTR record. This response record contains the service instance name "Xiao Li's Music Service._music._tcp.local." The client application can then extract the service instance name from the PTR record and add it to the server list. Figure 3 Service discovery process example 2.3 Service Resolution Service resolution is performed after service discovery is completed. The application selects the name of the service instance and multicasts the LAN to query the corresponding SRV record; after the service provider responds, it returns the current host name and port number of the service instance; after the application obtains the host name, it sends a multicast mDNS query request again to resolve the IP address corresponding to the host name. Finally, the application establishes a connection with the service instance based on the obtained IP address and port number to complete the resolution. Figure 4 Service resolution process example At this point, the entire process of automatic registration and discovery of the music sharing service has been completed, which is efficient and convenient, and does not require human participation. Through the established network channel, the client device can browse and play the relevant music resources on the server. After years of development, Bonjour has become a standard service for Apple and other platforms, providing an open, practical and efficient solution for zero-configuration networks. Bonjour is based on mDNS and DNS-SD protocols, making it highly compatible with existing network infrastructure. It has been widely used in personal, enterprise networks and IoT devices, greatly simplifying network configuration and management. In the future, with the continuous growth of smart hardware business, related technologies will have broad application and development prospects in network interconnection. References [1] Apple. Developer Resources - Bonjour [EB/OL]. (2023)[2023-07-21]. https://developer.apple.com/bonjour/. [2] Wu Yueqian. LAN Device Discovery: Bonjour Protocol [EB/OL]. (2016-09-28)[2023-07-21]. https://blog.csdn.net/yueqian_scut/article/details/52694411. [3] yuweifeng. Network Protocol mDNS20170217[EB/OL]. (2017-02-17)[2023-07-21]. https://www.cnblogs.com/yuweifeng/p/6409182.html. Author: Wang Jiankai Unit: China Mobile Smart Home Operation Center |
<<: Local temperature drops by more than 10℃! A new wave of cold air is coming
On January 23, the Central Meteorological Observa...
Your browser does not support the video tag The Q...
Copywriting is a job with a relatively low entry ...
People who often pay attention to health know tha...
This is a very common scenario. When you take on ...
The Institute of Vertebrate Paleontology and Pale...
To operate a community well, the key is to find t...
Xiaohongshu’s strategy has changed. Last year, it...
The survey covers multiple areas, including busin...
Around 3pm this afternoon, Apple CEO Tim Cook ope...
In the fossil exhibition areas of many natural mu...
The essence of user growth is to conduct precise ...
In nature, animals' hard structures basically...
[[198282]] The Network Security Configuration fea...
Tesla released a new Model S/X price adjustment p...