2

我正在尝试在 ns-3 中设置多跳 AdHoc 802.11g 网络。
首先,我使用了示例“wifi-simple-adhoc-grid.cc”。

该示例使用 UDP,但我想使用 TCP。所以我换了

TypeId tid = ns3::UdpSocketFactory::GetTypeId();
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

TypeId tid = ns3::TcpSocketFactory::GetTypeId();
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);

发送数据包是没有问题的,但是 ReceivePacket 永远不会被调用,这意味着套接字 Sink 没有接收到数据包。

整个代码:https ://gist.github.com/3023757

路由输出

Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> 
("wifi-multihop.routes", std::ios::out)
4

1 回答 1

0

您可以调用 SetRevCallback 函数您的 SetAcceptCallback 函数。

明确地说,

recvSink->SetAcceptCallback (MakeNullCallback<bool, Ptr<Socket>,const Address &> (),MakeCallback(&accept));

在接受函数中

void accept(Ptr<Socket> socket,const ns3::Address& from)
{

    std::cout<<"Connection accepted"<< std::endl;
    socket->SetRecvCallback (MakeCallback (&ReceivePacket));

}
于 2014-05-15T08:15:01.000 回答