36-2022 Shreya Jain - LAB 7 - Program For UPD-client-server Using NS3 (Ubuntu) and Java (In Eclipse)
36-2022 Shreya Jain - LAB 7 - Program For UPD-client-server Using NS3 (Ubuntu) and Java (In Eclipse)
36
Source Code:
#include<fstream>
#include "ns3/core-module.h"
#include "ns3/core-module.h”
#include"ns3/csma-module.h"
#include"ns3/applications-module
.h" #include
"ns3/internet-module.h"
NS_LOG_COMPONENT_DEFINE ("UdpClientServerExample");
int
main (int argc, char *argv[])
{
CommandLine cmd;
n.Create (2);
InternetStackHelper
internet; internet.Install
(n);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", DataRateValue
(DataRate (5000000))); csma.SetChannelAttribute ("Delay",
TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute ("Mtu",
UintegerValue (1400));
NS_LOG_INFO ("Assign IP
Addresses."); if (useV6 == false)
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Shreya Jain
36
Ipv4InterfaceContainer i = ipv4.Assign (d);
serverAddress = Address (i.GetAddress (1));
else
{
Ipv6AddressHelper ipv6;
ipv6.SetBase ("2001:0000:f00d:cafe::",
Ipv6Prefix (64)); Ipv6InterfaceContainer i6 =
ipv6.Assign (d); serverAddress =
Address(i6.GetAddress (1,1));
NS_LOG_INFO ("Create
4000;
NS_LOG_INFO ("Run
Simulation."); Simulator::Run ();
NS_LOG_INFO ("Done.");
Simulator::Destroy ();
}
Udp_Server.java:
package ppt;
server.receive(packet);
} }
Shreya Jain
36
➔ Udp_Client.java:
package ppt;
import
java.io.IOException;
import
java.net.DatagramPacket
; import
java.net.DatagramSocket
; import
java.net.InetAddress;
add=
InetAddress.getByName("localhost");
client.send(pkt);
Output:
● NetAnimation:
Shreya Jain
36