how to set the bind() function to receive the broadcast messages?

102 views
Skip to first unread message

Lu Tongxing

unread,
Jan 18, 2017, 7:54:56 AM1/18/17
to omn...@googlegroups.com


  P1---udpBasicApp

From P1, I use udpBasicAPP to broadcast message and receive it, it can work successfully. From the results of simulation, i can see that the udpBasicAPP has sent and received messages.

                                                                        P2---udpBasicAppCam

then i use a new App named udpBasicAppCam, that inherits the udpBasicAPP,  to broadcast message and receive it. 

but there are some problems about bind() function so that udpBasicAppCam can not receive messages
.


in the udpBasicApp,  it will runs the bind() function
void UDPBasicApp::processStart() {

  socket.setOutputGate(gate("udpOut"));
socket.bind(localPort);

    setSocketOptions();
}


now in my code, i use the UDPBasicAppCam to inhrits UDPBasicApp. you see,

 the code will come into UDPBasicApp::processStart() to run bind(), then here comse a mistake: localport already taken.
void UDPBasicAppCam::processStart() {
 UDPBasicApp::processStart();
}



the only way to solve the problem " localport already taken" is that i change my code like this:

void UDPBasicAppCam::processStart() {

// comment the processStart function out
// UDPBasicApp::processStart();

}

in this way, the code runs well, UDPBasicAppCam can send packets, but  UDPBasicAppCam and UDPBasicApp
can not receive the messages.

can anyone teach me to use the bind() function rightly?

Thank you very much.



Auto Generated Inline Image 1

Alfonso Ariza Quintana

unread,
Jan 18, 2017, 10:40:20 AM1/18/17
to omn...@googlegroups.com

Try this code

https://github.com/aarizaq/inetmanet-3.x/blob/inetmanet-2.2/src/applications/udpapp/UDPBasicFlooding.cc

 

It is a flooding implementation, it uses broadcast packets

 

If you want to stop the propagation to only one hop  you can if you modify the method processPacket

 

void UDPBasicFlooding::processPacket(cPacket *pk)

 

{

 

if (pk->getKind() == UDP_I_ERROR)

 

{

 

EV << "UDP error received\n";

 

delete pk;

 

return;

 

}

EV << "Received packet: " << UDPSocket::getReceivedPacketInfo(pk) << endl;

 

emit(rcvdPkSignal, pk);

 

numReceived++;

 

delete pk;

return;

}

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

Lu Tongxing

unread,
Jan 18, 2017, 11:27:58 AM1/18/17
to OMNeT++ Users, aari...@hotmail.com

dear Alfonso, thank you so much for your reply.

I have tried your way, but it does not work . i think the reason is :

void UDPBasicAppCam::handleMessage(cMessage * msg)
{
  
    if(msg=camTimer){
        CheckCamConditionTimer();
    } else if (msg->getKind() == UDP_I_DATA) {

            processPacket(PK(msg));

    }

}


UDPBasicAppCam should first receive the command UDP_I_DATA, then it will call the function processPacket() to receive the packets.

but now because the bind() function does not work, UDPBasicAppCam APP layer  can not receive the command UDP_I_DATA from lower layer, 

so UDPBasicAppCam Layer can not receive the packets.



在 2017年1月18日星期三 UTC+1下午4:40:20,Alfonso Ariza Quintana写道:

Alfonso Ariza Quintana

unread,
Jan 18, 2017, 11:51:55 AM1/18/17
to omn...@googlegroups.com

Send me the files, I will try to check the problem when I have some free time

Lu Tongxing

unread,
Jan 18, 2017, 12:23:13 PM1/18/17
to OMNeT++ Users, aari...@hotmail.com

Hi, dear Alfonso, I send  my file to you, you can find it in the attachments. You do me a lot of help, thank you!


在 2017年1月18日星期三 UTC+1下午5:51:55,Alfonso Ariza Quintana写道:
For Alfonso.tar.gz

Lu Tongxing

unread,
Jan 19, 2017, 11:53:24 AM1/19/17
to OMNeT++ Users, aari...@hotmail.com
Hi, dear Alfonso, have you any ideas to solve the problems?

 

在 2017年1月18日星期三 UTC+1下午5:51:55,Alfonso Ariza Quintana写道:

Send me the files, I will try to check the problem when I have some free time

Alfonso Ariza Quintana

unread,
Jan 20, 2017, 4:44:45 AM1/20/17
to omn...@googlegroups.com

You have several miss concepts about the class inherit. You have include in the derived class ‘UDPSocket socket’ variable,

This is the problem. This variable is  defined in the base class, any class derived from the base class can use this variable, but in the moment that you redefine this variable in your class, you cannot access to this variable, the base class register the port and if you class try to send a packet without register it cannot, but if you try to register you have registered two times the port.

 

There are other errors, for example

basicCamContainer * lastmcam = carCamGeneration(host, mobility);

 

You reserve memory in the method but you lost the reference to this memory, with this, in a long simulation you will end without memory and the simulation will crash, if don’t need the memory that you have reserved, you should delete it

 

delete(carCamGeneration(host, mobility));

 

or

 

basicCamContainer * lastmcam = carCamGeneration(host, mobility);

delete lastmcam;

LU,Tongxing

unread,
Jan 23, 2017, 8:49:33 AM1/23/17
to omn...@googlegroups.com
Dear Alfonso, thank you very much,  as your advices i change the code, now it works. It can broadcast and receive. Thanks again.

To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+unsubscribe@googlegroups.com.

Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "OMNeT++ Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/0DP-EOunJ4s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages