Simulate a continuous client-server communication in ns3

473 Views Asked by At

I want to simulate a simple continuous client-server request-response behaviour; i.e. the client sends a packet to server, then server receives the packet and responds to the client, then client receives the response packet and it again sends out a new packet to server and so on. I have figured out to send one round of communication (client->server->client) but don't know how to continue this. This is my code to achieve one round:

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (wifiApNode.Get (nWifiAp - 1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (apDevicesInterfaces.GetAddress (nWifiAp - 1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps;

clientApps = echoClient.Install (wifiStaNodes.Get (nWifiSta - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));

If I set any other int than 1 in echoClient.SetAttribute ("MaxPackets", UintegerValue (1));, I am able to have that many rounds but the problem is that they all start at 1 second gap (due to this: echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));). I want that client starts sending out as soon as it receives response from the server and not after waiting for 1 second.

1

There are 1 best solutions below

0
On

You will need to modify the echoClient application and in particularly the 'HandleRead' method that is respnsible for the reception of packets. Currently it only prints that one is received. Take a look at the UdpEchoServer application, where the HandleRead is generating the response.