简体   繁体   中英

OMNeT++ disassembling received messages

I want to read data from my received message in OMNeT++ and store it.

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'.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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