将消息从节点发送到其邻居
Sending a message from a node to its neighboors
我有一个节点网络,我想从 ID 401 标识的节点向其邻居发送消息。以下是我使用的代码:
for(int i = 0; i < 8; i++)
{
cMessage *copy = msg->dup();
send(copy, "out", i);
}
delete msg;
以下是我收到的错误消息
<!> Error in module (Node) topo. nd[401] (id=404) during network initialization: send()/sendDelayed(): Gate index 0 out of range when accessing vector gate `out[]' with size 0.
此错误意味着:
- 门
out
在文件中声明为NED
向量(可能是这样:output out[];
) - 门
out
尚未连接到任何其他节点(即它的大小等于 0)
您应该做的是将节点的门out
连接到每个其他节点的输入门。此外,我建议在 for 循环中检查out
向量的大小,例如:
for (int i = 0; i < gate("out", 0)->getVectorSize(); ++i) {
// ...
}
注意:仅当至少连接了一个out
端口时,上述代码才能正常工作。
相关文章:
- boost::进程间消息队列引发错误
- 在线编译器中的分段C++没有打印消息
- C++错误消息*成员参考.**初学者*
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 如何通过参数抛出错误消息
- 从服务器传输到客户端的消息不会出现
- ROS2 动态消息模板
- C++秘密消息学校作业
- glad 导致 glfwSwapBuffers 返回错误消息
- C++入门 5 版:类消息和文件夹
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 如何处理从一个对象传递到另一个在C++中具有公共抽象类的对象的消息
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- 如何将 Firebase 与基于 Linux 的客户端应用配合使用,以便与服务器进行双向消息通信
- 重新定义预定义的 errno 错误消息 (E2BIG)
- 将消息从节点发送到其邻居
- 将消息从节点发送到其邻居