Writing a service client
For service communication to work, you need a service server and a service client. As a reminder, you can only have one service server but multiple clients.
So far, we’ve finished our service server inside the number_counter
node. Now, let’s create a service client inside another node so that you can try the service.
Where will you write the code for the client? In a real application, you will create a service client in a node that needs to call the service. In terms of the battery and LED example from the beginning of this chapter, the LED panel node contains a service server. The battery node, which is responsible for monitoring the battery state, contains a service client that can send some requests to the server.
Then, when to send a request depends on the application. With the previous example, we decided that when the battery gets full or empty, we use the service client inside the node to send a request to the server so that we...