Reputation: 149
I have created a simulation in OMNeT++ where I have one client and one server (both of them are UDPBasicApp modules). The client sends packets to the server. The server also sends packets to the client, which are two subclasses of cPacket.
Unfortunately, there are conflicts between those two types of packets when they are received by the client. Let's assume that the types of the two packets are called FirstPacket and SecondPacket respectively (classes derived from cPacket). By running the simulation, as soon as the client receives the first packet from the server the simulation crashes and I get someting like the following error message:
"check_and_cast(): cannot cast (FirstPacket*).ClientServer.client.udpApp[0] to type SecondPacket"
How I can solve this problem? How the server can successfully receive both types of packets sent by the client?
Upvotes: 3
Views: 318
Reputation: 6943
You are probably using something like SecondPacket* p = check_and_cast<SecondPacket*>(pkt);
to force each incoming packet to be treated as being of type SecondPacket
. OMNeT++'s check_and_cast
will abort your simulation if this is not the case. A simple solution is to use a dynamic_cast
instead:
PacketTypeA* a = dynamic_cast<PacketTypeA*>(pkt);
PacketTypeB* b = dynamic_cast<PacketTypeB*>(pkt);
if (a) {
printf("got packet type A: %d", a->some_field_of_a);
}
if (b) {
printf("got packet type B: %d", b->some_field_of_b);
}
Upvotes: 4