ns-3 wlan grid TCP not working while UDP is

帅比萌擦擦* 提交于 2019-12-07 20:06:44

问题


I am trying to set up a Multihop AdHoc 802.11g Network in ns-3.
To get started I used the example 'wifi-simple-adhoc-grid.cc'.

The example uses UDP, but I want to use TCP. Therefore I switched

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));

to

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);

Sending Packets is no Problem, but ReceivePacket is never called, which means, that socket Sink receives no packets.

The whole code: https://gist.github.com/3023757

Routes output by:

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

回答1:


You can call SetRevCallback function your SetAcceptCallback function.

Explicitly,

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

In the accept function

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

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

}


来源:https://stackoverflow.com/questions/11274459/ns-3-wlan-grid-tcp-not-working-while-udp-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!