简体   繁体   English

OMNeT ++分解收到的消息

[英]OMNeT++ disassembling received messages

I want to read data from my received message in OMNeT++ and store it. 我想从收到的OMNeT ++消息中读取数据并将其存储。

This is what my message format looks like: 这是我的消息格式:

packet ServerMsg
{
    String code;
    String text;
}

I know how to build and send it, but not how to disassemble it at the receiving point. 我知道如何构建和发送它,但是不知道如何在接收点将其拆解。

Now I want to store 'code' in 'a' and 'text' in 'b'. 现在,我想将“代码”存储在“ a”中,将“文本”存储在“ b”中。

void Server::handleMessage(cMessage *msg) {
   String a;
   String b;
}

What's the way to go here? 去这里要走什么路?

You need to cast the incoming message to the appropriate type and then can access all the member variables of the message class: 您需要将传入的消息强制转换为适当的类型,然后可以访问消息类的所有成员变量:

#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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM