In this section, we are going to create ROS nodes, which can use the services definition that we defined already. The service nodes we are going to create can send a string message as a request to the server and the server node will send another message as a response.
Navigate to mastering_ros_demo_pkg/src, and find nodes with the names demo_service_server.cpp and demo_service_client.cpp.
The demo_service_server.cpp is the server, and its definition is as follows:
#include "ros/ros.h" #include "mastering_ros_demo_pkg/demo_srv.h" #include <iostream> #include <sstream> using namespace std; bool demo_service_callback(mastering_ros_demo_pkg::demo_srv::Request &req, mastering_ros_demo_pkg::demo_srv::Response &res) { std::stringstream ss; ss << "Received Here"; res.out = ss.str(); ...