20 #include "ns3/ipv4-address.h"
21 #include "ns3/ipv6-address.h"
22 #include "ns3/address-utils.h"
23 #include "ns3/nstime.h"
24 #include "ns3/inet-socket-address.h"
25 #include "ns3/inet6-socket-address.h"
26 #include "ns3/socket.h"
27 #include "ns3/udp-socket.h"
28 #include "ns3/simulator.h"
29 #include "ns3/socket-factory.h"
30 #include "ns3/packet.h"
31 #include "ns3/uinteger.h"
33 #include "udp-echo-server.h"
38 NS_OBJECT_ENSURE_REGISTERED (UdpEchoServer);
41 UdpEchoServer::GetTypeId (
void)
43 static TypeId tid = TypeId (
"ns3::UdpEchoServer")
44 .SetParent<Application> ()
45 .AddConstructor<UdpEchoServer> ()
46 .AddAttribute (
"Port",
"Port on which we listen for incoming packets.",
48 MakeUintegerAccessor (&UdpEchoServer::m_port),
49 MakeUintegerChecker<uint16_t> ())
54 UdpEchoServer::UdpEchoServer ()
59 UdpEchoServer::~UdpEchoServer()
83 m_socket->
Bind (local);
84 if (addressUtils::IsMulticast (m_local))
90 udpSocket->MulticastJoinGroup (0, m_local);
104 m_socket6->
Bind (local6);
105 if (addressUtils::IsMulticast (local6))
111 udpSocket->MulticastJoinGroup (0, local6);
148 while ((packet = socket->
RecvFrom (from)))
167 socket->
SendTo (packet, 0, from);
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
virtual void StartApplication(void)
Application specific startup code.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
void RemoveAllPacketTags(void)
Ptr< Node > GetNode() const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
virtual void DoDispose(void)
#define NS_LOG_LOGIC(msg)
virtual void DoDispose(void)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
static InetSocketAddress ConvertFrom(const Address &address)
Callback< R > MakeNullCallback(void)
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
void RemoveAllByteTags(void)
static bool IsMatchingType(const Address &addr)
If the address match.
uint16_t GetPort(void) const
Get the port.
virtual void StopApplication(void)
Application specific shutdown code.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
uint16_t GetPort(void) const
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
virtual int Close(void)=0
Close a socket.
a unique identifier for an interface.
static bool IsMatchingType(const Address &address)
static TypeId LookupByName(std::string name)