Writing a service server
You will now write your first service server. As mentioned previously, we will continue with the number application we started in the previous chapter. What we want to do here is allow number_counter
to reset the counter to a given number when we ask it to do so. This is a perfect example of when to use a service.
The first thing to think about when creating a new service is what service interface you need. We’ve just done that, so we can now focus on the code.
To write a service server, you will need to import the interface and then create a new service in the node’s constructor. You will also need to add a callback to be able to process the request, do the required action or computation, and return a response to the client.
As always, let’s start with a fully detailed explanation with Python, after which we will see how to do the same with C++.
Writing a Python service server
To write a Python service server, we first need...