A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
ns3tcp-socket-writer.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 University of Washington
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*/
17
18
#include "
ns3tcp-socket-writer.h
"
19
20
#include "ns3/packet.h"
21
#include "ns3/tcp-socket-factory.h"
22
23
namespace
ns3
24
{
25
26
SocketWriter::SocketWriter
()
27
: m_node(nullptr),
28
m_socket(nullptr),
29
m_isSetup(false),
30
m_isConnected(false)
31
{
32
}
33
34
SocketWriter::~SocketWriter
()
35
{
36
m_socket
=
nullptr
;
37
m_node
=
nullptr
;
38
}
39
40
/* static */
41
TypeId
42
SocketWriter::GetTypeId
()
43
{
44
static
TypeId
tid =
TypeId
(
"ns3::SocketWriter"
)
45
.
SetParent
<
Application
>()
46
.SetGroupName(
"Stats"
)
47
.AddConstructor<
SocketWriter
>();
48
return
tid;
49
}
50
51
void
52
SocketWriter::StartApplication
()
53
{
54
m_socket
=
Socket::CreateSocket
(
m_node
,
TcpSocketFactory::GetTypeId
());
55
m_socket
->
Bind
();
56
}
57
58
void
59
SocketWriter::StopApplication
()
60
{
61
}
62
63
void
64
SocketWriter::Setup
(
Ptr<Node>
node,
Address
peer)
65
{
66
m_peer
= peer;
67
m_node
= node;
68
m_isSetup
=
true
;
69
}
70
71
void
72
SocketWriter::Connect
()
73
{
74
if
(!
m_isSetup
)
75
{
76
NS_FATAL_ERROR
(
"Forgot to call Setup() first"
);
77
}
78
m_socket
->
Connect
(
m_peer
);
79
m_isConnected
=
true
;
80
}
81
82
void
83
SocketWriter::Write
(uint32_t numBytes)
84
{
85
if
(!
m_isConnected
)
86
{
87
Connect
();
88
}
89
Ptr<Packet>
packet = Create<Packet>(numBytes);
90
m_socket
->
Send
(packet);
91
}
92
93
void
94
SocketWriter::Close
()
95
{
96
m_socket
->
Close
();
97
}
98
}
// namespace ns3
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Application
The base class for all ns3 applications.
Definition:
application.h:62
ns3::Ptr< Node >
ns3::Socket::Send
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
ns3::Socket::Connect
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
ns3::Socket::CreateSocket
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:72
ns3::Socket::Close
virtual int Close()=0
Close a socket.
ns3::Socket::Bind
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
ns3::SocketWriter
Simple class to write data to sockets.
Definition:
ns3tcp-socket-writer.h:33
ns3::SocketWriter::m_peer
Address m_peer
Peer's address.
Definition:
ns3tcp-socket-writer.h:66
ns3::SocketWriter::SocketWriter
SocketWriter()
Definition:
ns3tcp-socket-writer.cc:26
ns3::SocketWriter::~SocketWriter
~SocketWriter() override
Definition:
ns3tcp-socket-writer.cc:34
ns3::SocketWriter::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
ns3tcp-socket-writer.cc:42
ns3::SocketWriter::Connect
void Connect()
Connect the socket.
Definition:
ns3tcp-socket-writer.cc:72
ns3::SocketWriter::Setup
void Setup(Ptr< Node > node, Address peer)
Setup the socket.
Definition:
ns3tcp-socket-writer.cc:64
ns3::SocketWriter::Write
void Write(uint32_t numBytes)
Write to the socket.
Definition:
ns3tcp-socket-writer.cc:83
ns3::SocketWriter::m_node
Ptr< Node > m_node
Node pointer.
Definition:
ns3tcp-socket-writer.h:67
ns3::SocketWriter::Close
void Close()
Close the socket.
Definition:
ns3tcp-socket-writer.cc:94
ns3::SocketWriter::m_isSetup
bool m_isSetup
True if the socket is connected.
Definition:
ns3tcp-socket-writer.h:69
ns3::SocketWriter::StopApplication
void StopApplication() override
Application specific shutdown code.
Definition:
ns3tcp-socket-writer.cc:59
ns3::SocketWriter::m_socket
Ptr< Socket > m_socket
Socket.
Definition:
ns3tcp-socket-writer.h:68
ns3::SocketWriter::m_isConnected
bool m_isConnected
True if the socket setup has been done.
Definition:
ns3tcp-socket-writer.h:70
ns3::SocketWriter::StartApplication
void StartApplication() override
Application specific startup code.
Definition:
ns3tcp-socket-writer.cc:52
ns3::TcpSocketFactory::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
tcp-socket-factory.cc:30
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3tcp-socket-writer.h
src
test
ns3tcp
ns3tcp-socket-writer.cc
Generated on Sun Mar 3 2024 17:11:08 for ns-3 by
1.9.1