Nebula
Loading...
Searching...
No Matches
stdtcpclient.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
26#include "core/refcounted.h"
28#include "net/socket/socket.h"
29#include "io/stream.h"
30
31//------------------------------------------------------------------------------
32namespace Net
33{
35{
37public:
47 virtual ~StdTcpClient();
49 void SetBlocking(bool b);
51 bool IsBlocking() const;
53 void SetServerAddress(const IpAddress& addr);
55 const IpAddress& GetServerAddress() const;
59 void Disconnect();
61 bool IsConnected();
63 bool Send();
67 bool Recv();
70
71protected:
78};
79
80//------------------------------------------------------------------------------
83inline void
85{
86 this->blocking = b;
87 if (this->socket.isvalid())
88 {
89 this->socket->SetBlocking(b);
90 }
91}
92
93//------------------------------------------------------------------------------
96inline bool
98{
99 return this->blocking;
100}
101
102//------------------------------------------------------------------------------
105inline void
107{
108 this->serverAddr = addr;
109}
110
111//------------------------------------------------------------------------------
114inline const IpAddress&
116{
117 return this->serverAddr;
118}
119
120} // namespace Net
121//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:38
Represents an IP address, consisting of a IPv4 host address and a port number.
A TcpClient object is used to communicate with a TcpServer.
Definition stdtcpclient.h:35
void SetBlocking(bool b)
enable/disable blocking behaviour
Definition stdtcpclient.h:84
bool Recv()
receive data from server into recv stream
Definition stdtcpclient.cc:234
Ptr< IO::Stream > sendStream
Definition stdtcpclient.h:75
Ptr< IO::Stream > recvStream
Definition stdtcpclient.h:76
bool blocking
Definition stdtcpclient.h:74
StdTcpClient()
constructor
Definition stdtcpclient.cc:20
bool IsConnected()
return true if currently connected
Definition stdtcpclient.cc:107
bool inConnectionState
Definition stdtcpclient.h:77
virtual ~StdTcpClient()
destructor
Definition stdtcpclient.cc:32
Result Connect()
establish a connection with the server
Definition stdtcpclient.cc:52
void SetServerAddress(const IpAddress &addr)
set the server address to connect to
Definition stdtcpclient.h:106
Result
Definition stdtcpclient.h:39
@ Connecting
Definition stdtcpclient.h:42
@ Success
Definition stdtcpclient.h:41
@ Error
Definition stdtcpclient.h:40
const IpAddress & GetServerAddress() const
get the server address
Definition stdtcpclient.h:115
__DeclareClass(StdTcpClient)
void Disconnect()
disconnect from the server
Definition stdtcpclient.cc:132
const Ptr< IO::Stream > & GetRecvStream()
access to recv stream
Definition stdtcpclient.cc:274
Ptr< Socket > socket
Definition stdtcpclient.h:72
bool IsBlocking() const
get blocking behaviour
Definition stdtcpclient.h:97
const Ptr< IO::Stream > & GetSendStream()
access to send stream
Definition stdtcpclient.cc:265
IpAddress serverAddr
Definition stdtcpclient.h:73
bool Send()
send accumulated content of send stream to server
Definition stdtcpclient.cc:147
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Definition debugmessage.h:20