2.2.1 Service Communication Theoretical Model
Service communication is somewhat simpler than topic communication. The theoretical model is shown in the figure below. This model involves three roles:
- ROS Master (Manager)
- Server (Service Provider)
- Client (Service Requester)
The ROS Master is responsible for storing the registration information of Servers and Clients. It matches Servers and Clients that offer/request the same service by name and helps them establish a connection. After the connection is established, the Client sends a request message, and the Server returns a response message.

The entire process is implemented through the following steps:
0. Server Registration
After startup, the Server registers its own information with the ROS Master via RPC, which includes the name of the service it provides. The ROS Master adds the node's registration information to its registry.
1. Client Registration
After startup, the Client also registers its own information with the ROS Master via RPC, which includes the name of the service it needs to request. The ROS Master adds the node's registration information to its registry.
2. ROS Master Performs Information Matching
The ROS Master matches Servers and Clients based on the information in its registry and sends the Server's TCP address information to the Client via RPC.
3. Client Sends Request
Based on the information received in step 2, the Client establishes a network connection with the Server using TCP and sends the request data.
4. Server Sends Response
The Server receives and parses the request data, generates a response result, and returns it to the Client.
Note:
- When a client request is processed, it must be ensured that the server has already started;
- Multiple servers and multiple clients can exist.