ClientServer/simple有感

本文介绍了一个简单的客户端-服务器接口示例。客户端SimpleClient通过单一会话连接到服务器SimpleServer,后者实现为静态链接的DLL。文章还提到了构建顺序及使用的几个关键类:RSessionBase用于客户端会话,CServer2是服务器基类,CSession2是服务器的会话类。

Description

This pair of examples shows a simple use of the client server interface. The client, SimpleClient, has a single session with the server SimpleServer, implemented as a statically linked DLL.


Build Notes

The server must be built before the client. This requirement is specified in the component description file, bld.inf. SimpleServer.mmp is listed before SimpleClient.mmp. Build activities relating to particular .mmp files are carried out in the order in which they are listed in the bld.inf file.


Classes used

  • RSessionBase: client side session

  • CServer2: the server base class

  • CSession2: the server's session class

 

 

一个server应该指一个exe吧。
这个exe要实现特定的类而已。

 

server实现一般用到CServer2和CSession2
client端实现RSessionBase

### ROS 中 `SimpleActionClient` 的头文件及使用方法 在ROS中,`SimpleActionClient` 是 `actionlib` 库提供的一个类,用于简化Action客户端的开发。通过该类,可以方便地向Action服务器发送目标、接收反馈以及处理最终结果。该类的定义位于 `actionlib/client/simple_action_client.h` 头文件中[^1]。 #### 基本使用方式 要使用 `SimpleActionClient`,首先需要包含对应的头文件: ```cpp #include <actionlib/client/simple_action_client.h> ``` 接着,需要指定Action的类型,通常包括目标(Goal)、结果(Result)、反馈(Feedback)等消息类型。例如,假设使用的Action消息类型为 `s_c_demo::demoAction`,则可以定义如下客户端: ```cpp typedef actionlib::SimpleActionClient<s_c_demo::demoAction> DemoClient; ``` 在 `main` 函数中,初始化ROS节点后,创建 `SimpleActionClient` 实例并连接到目标Action服务器: ```cpp DemoClient client("action_demo", true); // "action_demo" 为服务器名称 client.waitForServer(); // 等待服务器启动 ``` 发送目标并等待执行结果的示例代码如下: ```cpp s_c_demo::demoGoal goal; goal.goal = 10; // 设置目标值 client.sendGoal(goal); // 发送目标 client.waitForResult(); // 等待执行完成 ``` 若需要处理执行结果,可注册回调函数,例如: ```cpp client.sendGoal(goal, &donecb); // donecb 为完成回调函数 ``` 其中 `donecb` 的定义如下: ```cpp void donecb(const actionlib::SimpleClientGoalState& state, const s_c_demo::demoResultConstPtr& result) { if (state == actionlib::SimpleClientGoalState::SUCCEEDED) { ROS_INFO("Goal succeeded! Result: %d", result->result); } else { ROS_INFO("Goal failed!"); } } ``` #### 与其他组件的协作 `SimpleActionClient` 通常与 `SimpleActionServer` 配合使用,实现完整的Action通信机制。客户端通过发送目标请求启动长时间任务,服务器端接收目标并执行任务,同时可周期性地发布反馈信息,最后返回执行结果[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值