Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::TcpClient Class Reference

Network class that represents a client in a TCP connection. More...

Inheritance diagram for Nz::TcpClient:
Nz::AbstractSocket Nz::Stream

Public Member Functions

 TcpClient ()
 Constructs a TcpClient object by default.
 
 TcpClient (TcpClient &&tcpClient)=default
 
SocketState Connect (const IpAddress &remoteAddress)
 Connects to the IpAddress. More...
 
SocketState Connect (const String &hostName, NetProtocol protocol=NetProtocol_Any, const String &service="http", ResolveError *error=nullptr)
 Connects to the hostname. More...
 
void Disconnect ()
 Disconnects the connection. More...
 
void EnableLowDelay (bool lowDelay)
 Enables low delay in emitting. More...
 
void EnableKeepAlive (bool keepAlive, UInt64 msTime=10000, UInt64 msInterval=1000)
 Enables the keep alive flag. More...
 
bool EndOfStream () const override
 Checks whether the stream reached the end of the stream. More...
 
UInt64 GetCursorPos () const override
 Gets the position of the cursor. More...
 
UInt64 GetKeepAliveInterval () const
 Gets the interval between two keep alive pings. More...
 
UInt64 GetKeepAliveTime () const
 Gets the time before expiration of connection. More...
 
IpAddress GetRemoteAddress () const
 Gets the remote address. More...
 
UInt64 GetSize () const override
 Gets the size of the raw memory available. More...
 
bool IsLowDelayEnabled () const
 Checks whether low delay is enabled. More...
 
bool IsKeepAliveEnabled () const
 Checks whether the keep alive flag is enabled. More...
 
bool Receive (void *buffer, std::size_t size, std::size_t *received)
 Receives the data available. More...
 
bool ReceivePacket (NetPacket *packet)
 Receives the packet available. More...
 
bool Send (const void *buffer, std::size_t size, std::size_t *sent)
 Sends the data available. More...
 
bool SendMultiple (const NetBuffer *buffers, std::size_t bufferCount, std::size_t *sent)
 Sends multiple buffers at once. More...
 
bool SendPacket (const NetPacket &packet)
 Sends the packet available. More...
 
bool SetCursorPos (UInt64 offset) override
 Sets the position of the cursor. More...
 
bool WaitForConnected (UInt64 msTimeout=3000)
 Waits for being connected before time out. More...
 
TcpClientoperator= (TcpClient &&tcpClient)=default
 
- Public Member Functions inherited from Nz::AbstractSocket
 AbstractSocket (const AbstractSocket &)=delete
 
 AbstractSocket (AbstractSocket &&abstractSocket)
 Constructs a AbstractSocket object with another one by move semantic. More...
 
virtual ~AbstractSocket ()
 Destructs the object and calls Close. More...
 
void Close ()
 Closes the socket.
 
void EnableBlocking (bool blocking)
 Enables blocking. More...
 
SocketError GetLastError () const
 Gets the last error. More...
 
SocketHandle GetNativeHandle () const
 Gets the internal socket handle. More...
 
SocketState GetState () const
 Gets the internal state. More...
 
SocketType GetType () const
 Gets the internal type. More...
 
bool IsBlockingEnabled () const
 Checks whether the blocking is enabled. More...
 
std::size_t QueryAvailableBytes () const
 Queries the available bytes. More...
 
std::size_t QueryReceiveBufferSize () const
 Queries the maximum socket receive buffer size. More...
 
std::size_t QuerySendBufferSize () const
 Queries the maximum socket send buffer size. More...
 
void SetReceiveBufferSize (std::size_t size)
 Sets the maximum receive buffer size. More...
 
void SetSendBufferSize (std::size_t size)
 Sets the maximum send buffer size. More...
 
AbstractSocketoperator= (const AbstractSocket &)=delete
 
AbstractSocketoperator= (AbstractSocket &&abstractSocket)
 Moves the AbstractSocket into this. More...
 
 NazaraSignal (OnStateChange, const AbstractSocket *, SocketState)
 
- Public Member Functions inherited from Nz::Stream
 Stream (const Stream &)=default
 
 Stream (Stream &&)=default
 
virtual ~Stream ()
 Destructs the object.
 
void EnableTextMode (bool textMode)
 Enables the text mode. More...
 
void Flush ()
 Flushes the stream. More...
 
virtual String GetDirectory () const
 Gets the directory of the stream. More...
 
virtual String GetPath () const
 Gets the path of the stream. More...
 
OpenModeFlags GetOpenMode () const
 Gets the open mode of the stream. More...
 
StreamOptionFlags GetStreamOptions () const
 Gets the options of the stream. More...
 
std::size_t Read (void *buffer, std::size_t size)
 Reads the stream and puts the result in a buffer. More...
 
virtual String ReadLine (unsigned int lineSize=0)
 Reads a line from the stream. More...
 
bool IsReadable () const
 Checks whether the stream is readable. More...
 
bool IsSequential () const
 Checks whether the stream is sequential. More...
 
bool IsTextModeEnabled () const
 Checks whether the stream has text mode enabled. More...
 
bool IsWritable () const
 Checks whether the stream can be written. More...
 
bool Write (const ByteArray &byteArray)
 Writes a ByteArray into the stream. More...
 
bool Write (const String &string)
 Writes a String into the stream. More...
 
std::size_t Write (const void *buffer, std::size_t size)
 Writes in the stream the content of a buffer. More...
 
Streamoperator= (const Stream &)=default
 
Streamoperator= (Stream &&)=default
 

Friends

class TcpServer
 

Additional Inherited Members

- Protected Member Functions inherited from Nz::AbstractSocket
 AbstractSocket (SocketType type)
 Constructs a AbstractSocket object with a type.
 
bool Open (NetProtocol protocol)
 Opens the socket according to a net protocol. More...
 
void Open (SocketHandle existingHandle)
 Opens the socket according to a socket handle. More...
 
void UpdateState (SocketState newState)
 Updates the state of the socket. More...
 
- Protected Member Functions inherited from Nz::Stream
 Stream (StreamOptionFlags streamOptions=StreamOption_None, OpenModeFlags openMode=OpenMode_NotOpen)
 Constructs a Stream object with options. More...
 
- Protected Attributes inherited from Nz::AbstractSocket
NetProtocol m_protocol
 
SocketError m_lastError
 
SocketHandle m_handle
 
SocketState m_state
 
SocketType m_type
 
bool m_isBlockingEnabled
 
- Protected Attributes inherited from Nz::Stream
OpenModeFlags m_openMode
 
StreamOptionFlags m_streamOptions
 

Detailed Description

Network class that represents a client in a TCP connection.

Member Function Documentation

◆ Connect() [1/2]

SocketState Nz::TcpClient::Connect ( const IpAddress remoteAddress)

Connects to the IpAddress.

Returns
State of the socket
Parameters
remoteAddressAddress to connect to
Remarks
Produces a NazaraAssert if remote is invalid
Produces a NazaraAssert if remote's port is not specified

◆ Connect() [2/2]

SocketState Nz::TcpClient::Connect ( const String hostName,
NetProtocol  protocol = NetProtocol_Any,
const String service = "http",
ResolveError *  error = nullptr 
)

Connects to the hostname.

Returns
State of the socket
Parameters
hostNameHostname of the remote
protocolNet protocol to use
serviceSpecify the protocol used
errorOptional argument to get the error

◆ Disconnect()

void Nz::TcpClient::Disconnect ( )
inline

Disconnects the connection.

See also
Close

◆ EnableKeepAlive()

void Nz::TcpClient::EnableKeepAlive ( bool  keepAlive,
UInt64  msTime = 10000,
UInt64  msInterval = 1000 
)

Enables the keep alive flag.

Parameters
keepAliveShould the connection be kept alive
msTimeTime in milliseconds before expiration
msIntervalInterval in milliseconds between two pings

◆ EnableLowDelay()

void Nz::TcpClient::EnableLowDelay ( bool  lowDelay)

Enables low delay in emitting.

Parameters
lowDelayShould low delay be used
Remarks
This may produce lag

◆ EndOfStream()

bool Nz::TcpClient::EndOfStream ( ) const
overridevirtual

Checks whether the stream reached the end of the stream.

Returns
true if there is no more available bytes

Implements Nz::Stream.

◆ GetCursorPos()

UInt64 Nz::TcpClient::GetCursorPos ( ) const
overridevirtual

Gets the position of the cursor.

Returns
0
Remarks
Produces a NazaraError because it is a special stream

Implements Nz::Stream.

◆ GetKeepAliveInterval()

UInt64 Nz::TcpClient::GetKeepAliveInterval ( ) const
inline

Gets the interval between two keep alive pings.

Returns
Interval in milliseconds between two pings

◆ GetKeepAliveTime()

UInt64 Nz::TcpClient::GetKeepAliveTime ( ) const
inline

Gets the time before expiration of connection.

Returns
Time in milliseconds before expiration

◆ GetRemoteAddress()

IpAddress Nz::TcpClient::GetRemoteAddress ( ) const
inline

Gets the remote address.

Returns
Address of peer

◆ GetSize()

UInt64 Nz::TcpClient::GetSize ( ) const
overridevirtual

Gets the size of the raw memory available.

Returns
Size of the memory available

Implements Nz::Stream.

◆ IsKeepAliveEnabled()

bool Nz::TcpClient::IsKeepAliveEnabled ( ) const
inline

Checks whether the keep alive flag is enabled.

Returns
true If it is the case

◆ IsLowDelayEnabled()

bool Nz::TcpClient::IsLowDelayEnabled ( ) const
inline

Checks whether low delay is enabled.

Returns
true If it is the case

◆ Receive()

bool Nz::TcpClient::Receive ( void *  buffer,
std::size_t  size,
std::size_t *  received 
)

Receives the data available.

Returns
true If data received
Parameters
bufferRaw memory to write
sizeSize of the buffer
receivedOptional argument to get the number of bytes received
Remarks
Produces a NazaraAssert if socket is invalid
Produces a NazaraAssert if buffer and its size is invalid

◆ ReceivePacket()

bool Nz::TcpClient::ReceivePacket ( NetPacket packet)

Receives the packet available.

Returns
true If packet received
Parameters
packetPacket to receive
Remarks
Produces a NazaraAssert if packet is invalid
Produces a NazaraAssert if packet size is inferior to the header size
Produces a NazaraWarning if packet's header is invalid

◆ Send()

bool Nz::TcpClient::Send ( const void *  buffer,
std::size_t  size,
std::size_t *  sent 
)

Sends the data available.

Returns
true If data sended
Parameters
bufferRaw memory to read
sizeSize of the buffer
sentOptional argument to get the number of bytes sent
Remarks
Large sending are handled, you do not need to call this multiple time
Produces a NazaraAssert if socket is invalid
Produces a NazaraAssert if buffer and its size is invalid

◆ SendMultiple()

bool Nz::TcpClient::SendMultiple ( const NetBuffer *  buffers,
std::size_t  bufferCount,
std::size_t *  sent 
)

Sends multiple buffers at once.

Returns
true If data were sent
Parameters
buffersA pointer to an array of NetBuffer containing buffers and size data
sizeNumber of NetBuffer to send
sentOptional argument to get the number of bytes sent

◆ SendPacket()

bool Nz::TcpClient::SendPacket ( const NetPacket packet)

Sends the packet available.

Returns
true If packet sent
Parameters
packetPacket to send
Remarks
Produces a NazaraError if packet could not be prepared for sending

◆ SetCursorPos()

bool Nz::TcpClient::SetCursorPos ( UInt64  offset)
overridevirtual

Sets the position of the cursor.

Returns
false
Parameters
offsetOffset according to the beginning of the stream
Remarks
Produces a NazaraError because it is a special stream

Implements Nz::Stream.

◆ WaitForConnected()

bool Nz::TcpClient::WaitForConnected ( UInt64  msTimeout = 3000)

Waits for being connected before time out.

Returns
true If connection is successful
Parameters
msTimeoutTime in milliseconds before time out
Remarks
Produces a NazaraAssert if socket is invalid

The documentation for this class was generated from the following files: