Data into UDP packet

39 views
Skip to first unread message

Omaima Younsi

unread,
Nov 17, 2022, 8:17:09 AM11/17/22
to OMNeT++ Users
I want to add data or message to UDP packet.

void UdpBasicApp::sendPacket()
{
    std::ostringstream str;
    str << packetName << "-" << numSent;
    Packet *packet = new Packet(str.str().c_str());
    if(dontFragment)
        packet->addTag<FragmentationReq>()->setDontFragment(true);
    const auto& payload = makeShared<ApplicationPacket>();
    payload->setChunkLength(B(par("messageLength")));

    payload->setSequenceNumber(numSent);
    payload->addTag<CreationTimeTag>()->setCreationTime(simTime());
    packet->insertAtBack(payload);
    L3Address destAddr = chooseDestAddr();
    emit(packetSentSignal, packet);
    socket.sendTo(packet, destAddr, destPort);
    numSent++;
}

This is the UDP source code for sending the packet, any ideas on how to add a test message that will be sent.

stefan.s...@hm.edu

unread,
Nov 18, 2022, 3:29:51 AM11/18/22
to OMNeT++ Users
Take a look here https://inet.omnetpp.org/docs/developers-guide/ch-packets.html#representing-data on how to create custom packets to use your data/message you want to send. This Packet will be used
instead of  "makeShared<ApplicationPacket>();" in the  send Packet() method.

Omaima Younsi

unread,
Nov 21, 2022, 11:41:13 AM11/21/22
to OMNeT++ Users
Thank you stefan that documentation really helped
Reply all
Reply to author
Forward
0 new messages