A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3tcp-socket-writer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "ns3/packet.h"
10#include "ns3/tcp-socket-factory.h"
11
12namespace ns3
13{
14
16 : m_node(nullptr),
17 m_socket(nullptr),
18 m_isSetup(false),
19 m_isConnected(false)
20{
21}
22
24{
25 m_socket = nullptr;
26 m_node = nullptr;
27}
28
29/* static */
32{
33 static TypeId tid = TypeId("ns3::SocketWriter")
35 .SetGroupName("Stats")
36 .AddConstructor<SocketWriter>();
37 return tid;
38}
39
40void
46
47void
51
52void
54{
55 m_peer = peer;
56 m_node = node;
57 m_isSetup = true;
58}
59
60void
62{
63 if (!m_isSetup)
64 {
65 NS_FATAL_ERROR("Forgot to call Setup() first");
66 }
68 m_isConnected = true;
69}
70
71void
73{
74 if (!m_isConnected)
75 {
76 Connect();
77 }
78 Ptr<Packet> packet = Create<Packet>(numBytes);
79 m_socket->Send(packet);
80}
81
82void
87} // namespace ns3
a polymophic address class
Definition address.h:90
The base class for all ns3 applications.
Definition application.h:51
Smart pointer class similar to boost::intrusive_ptr.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition socket.cc:61
virtual int Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
Simple class to write data to sockets.
Address m_peer
Peer's address.
static TypeId GetTypeId()
Register this type.
void Connect()
Connect the socket.
void Setup(Ptr< Node > node, Address peer)
Setup the socket.
void Write(uint32_t numBytes)
Write to the socket.
Ptr< Node > m_node
Node pointer.
void Close()
Close the socket.
bool m_isSetup
True if the socket is connected.
void StopApplication() override
Application specific shutdown code.
Ptr< Socket > m_socket
Socket.
bool m_isConnected
True if the socket setup has been done.
void StartApplication() override
Application specific startup code.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.