about ns3::Socket.SetRecvCallback

1,011 views
Skip to first unread message

Bo Zhang

unread,
Apr 7, 2010, 3:29:59 PM4/7/10
to ns-3-users
I have a function called

void ReceiveData(ns3::Ptr<ns3::Socket> socket) {
Ptr<Packet> msg = socket->Recv();
....
}

and later in the code, I have:

Ptr<Socket> data_sink;
....
data_sink->SetRecvCallback(MakeCallback(&ReceiveData));


So that ReceiveData is notified whenever the socket has packet
available to be read.

My plan is to update some local variables/storages each time a new
data packet is received. Imagine in a network, each node has its own
state, including data currently in possess, received data sequence
number etc. Each incoming data should cause a state change. But
apparently I could not pass extra arguments to ReceiveData via
callback, or I could, but don't know how to do that.

doxygen mentioned in ns3::Socket section:

SetRecvCallback (Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.


Could anyone explain to me about how my ReceiveData could update local
variables?


Thanks a lot

Zhang Bo

Mathieu Lacage

unread,
Apr 8, 2010, 4:47:46 AM4/8/10
to ns-3-...@googlegroups.com

class MyReceiver
{
public:
void RecvCallback (Ptr<Socket> sock);
private:
// private variables
};

MyReceiver receiver;
sock->SetRecvCallback (MakeCallback (&MyReceiver::RecvCallback, &receiver));

If you create the socket from a subclass of the Application class
(like OnOffApplication), you can easily set the RecvCallback to a
method of your application.

Mathieu
--
Mathieu Lacage <mathieu...@gmail.com>

Bo Zhang

unread,
Apr 8, 2010, 5:16:53 AM4/8/10
to ns-3-users
I see~~Thanks a lot. I'm gonna try that out.


Zhang Bo


On Apr 8, 4:47 pm, Mathieu Lacage <mathieu.lac...@gmail.com> wrote:

> Mathieu Lacage <mathieu.lac...@gmail.com>

路易斯

unread,
Oct 22, 2014, 11:10:09 PM10/22/14
to ns-3-...@googlegroups.com
thanks a lot.

Bo Zhang於 2010年4月8日星期四UTC+8上午3時29分59秒寫道:
Reply all
Reply to author
Forward
0 new messages