sending packet in omnetpp, as custom class message object

52 Views Asked by At

my message class is looks like this ..

message Custom {
    string src;
    
    float xPos;
    float yPos;
    bool target;
}

i have extended the UdpBasicApp to send the this custom message class..

In sendpacket() ..i have code like this ..

        const char* sourceModuleName = getParentModule()->getFullName();

        // Get the current position of the node
        IMobility* mobilityModule = check_and_cast<IMobility*>(getParentModule()->getSubmodule("mobility"));
        Coord currentPosition = mobilityModule->getCurrentPosition();

        EV_INFO << " (Original: " << currentPosition.x << ")" << endl;
        EV_INFO << "(Original: " << currentPosition.y << ")" << endl;

        std::ostringstream str;
        std::string packetNameStr = "CustomPacket"; // Set an appropriate name for the packet
        const char* packetName = packetNameStr.c_str();

        Custom *customPacket = new Custom(packetName);
        customPacket->setXPos(currentPosition.x);
        customPacket->setYPos(currentPosition.y);
        customPacket->setSrc(sourceModuleName);
        customPacket->setTarget(false);
        cMemCommBuffer buffer;
        customPacket->parsimPack(&buffer);
        inet::Packet *inetPacket = new inet::Packet("CustomPacket");
        inetPacket->insertAtBack(customPacket);
       socket.sendTo(inetPacket, destAddr, destPort);

but i am having the error ... since socket.sendTo() only sends the data of packet , and i am having custom packet and i cannot do this thing also.inetPacket->insertAtBack(customPacket);..Please guide through the situation ...Thanks in Advance

0

There are 0 best solutions below