Reputation: 76
Let's say i created my own packet called myPacket. Is there a way i can send it using socket.sendTo()
?
I know socket.sendTo()
takes in an INET packet so is there a way to convert myPacket into an INET packet?
The module that is going to receive the packet is Radio. I checked Radio's functions and they take in an inet packet so what can i do about it?
Signal *Radio::createSignal(Packet *packet) const
{
encapsulate(packet);
if (sendRawBytes) {
auto rawPacket = new Packet(packet->getName(), packet->peekAllAsBytes());
rawPacket->copyTags(*packet);
delete packet;
packet = rawPacket;
}
Signal *signal = check_and_cast<Signal *>(medium->transmitPacket(this, packet));
ASSERT(signal->getDuration() != 0);
return signal;
}
Upvotes: 3
Views: 752
Reputation: 463
You need to do 4 steps:
inet/applications/base/ApplicationPacket.msg
as an example.UdpBasicApp::sendPacket()
at inet/applications/udpapp/UdpBasicApp.cc
as an example.handleMessage
method or similar one to catch all possible messages my receiver can receive and process. All such methods take cMessage* msg
as an argument and then at the beginning:Packet* packet = check_and_cast<Packet*>(msg);
if (!packet) {
return;
}
const auto& payload = packet->peekAtFront<YourOwnPacketClass>();
// work with you message body...
Upvotes: 0
Reputation: 174
Basically, messages sent by using the cSimpleModule basic member function send(). This method is used to send messages to other modules through gates. One can also use the scheduleAt() to send a message at specific point in time.
If you use a higher level application such as http or tcp applications, so you are most probably going to use sockets. Sockets also use send() and scheduleAt() to send messages through gates.
Upvotes: 0
Reputation: 174
Sending messages using sockets needs a socket on the other side. If you have a socket at the other side so go ahead and send your message using a socket.
Upvotes: 0