src/applications/udp-echo/udp-echo-server.cc
changeset 2494 1c69ea12779c
parent 2257 71a58e70c671
child 2602 d9262bff6df2
--- a/src/applications/udp-echo/udp-echo-server.cc	Tue Feb 26 23:27:19 2008 +0100
+++ b/src/applications/udp-echo/udp-echo-server.cc	Wed Feb 27 00:05:23 2008 +0100
@@ -24,23 +24,32 @@
 #include "ns3/simulator.h"
 #include "ns3/socket-factory.h"
 #include "ns3/packet.h"
+#include "ns3/uinteger.h"
 
 #include "udp-echo-server.h"
 
 namespace ns3 {
 
 NS_LOG_COMPONENT_DEFINE ("UdpEchoServerApplication");
+NS_OBJECT_ENSURE_REGISTERED (UdpEchoServer);
 
-UdpEchoServer::UdpEchoServer (
-  Ptr<Node> n,
-  uint16_t port)
-: 
-  Application(n)
+TypeId
+UdpEchoServer::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("UdpEchoServer")
+    .SetParent<Application> ()
+    .AddConstructor<UdpEchoServer> ()
+    .AddAttribute ("Port", "Client Port",
+                   Uinteger (0),
+                   MakeUintegerAccessor (&UdpEchoServer::m_port),
+                   MakeUintegerChecker<uint16_t> ())
+    ;
+  return tid;
+}
+
+UdpEchoServer::UdpEchoServer ()
 {
   NS_LOG_FUNCTION;
-  NS_LOG_PARAMS (this << n << port);
-
-  Construct (n, port);
 }
 
 UdpEchoServer::~UdpEchoServer()
@@ -49,21 +58,6 @@
 }
 
 void
-UdpEchoServer::Construct (
-  Ptr<Node> n,
-  uint16_t port)
-{
-  NS_LOG_FUNCTION;
-  NS_LOG_PARAMS (this << n << port);
-
-  m_node = n;
-  m_port = port;
-
-  m_socket = 0;
-  m_local = InetSocketAddress (Ipv4Address::GetAny (), port);
-}
-
-void
 UdpEchoServer::DoDispose (void)
 {
   NS_LOG_FUNCTION;
@@ -81,7 +75,8 @@
       Ptr<SocketFactory> socketFactory = 
         GetNode ()->GetObject<SocketFactory> (tid);
       m_socket = socketFactory->CreateSocket ();
-      m_socket->Bind (m_local);
+      InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
+      m_socket->Bind (local);
     }
 
   m_socket->SetRecvCallback(MakeCallback(&UdpEchoServer::Receive, this));