Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从 OMNeT++ 中收到的消息中读取数据并将其存储。
这是我的消息格式:
packet ServerMsg { String code; String text; }
我知道如何构建和发送它,但不知道如何在接收点拆卸它。
现在我想将“代码”存储在“a”中,将“文本”存储在“b”中。
void Server::handleMessage(cMessage *msg) { String a; String b; }
去这里的路是什么?
您需要将传入的消息转换为适当的类型,然后才能访问消息类的所有成员变量:
#include "ServerMsg_m.h" ... void Server::handleMessage(cMessage *msg) { String a; String b; ServerMsg *pkt = check_and_cast<ServerMsg *>(msg); a = pkt->a; b = pkt->b; }