Ocean
Ocean::Network::ConnectionOrientedClient Class Reference

This class is the base class for all connection oriented clients. More...

Inheritance diagram for Ocean::Network::ConnectionOrientedClient:

Public Types

typedef Callback< void, const void *, const size_t > ReceiveCallback
 Definition of a data receive callback function. More...
 
typedef Callback< void > DisconnectCallback
 Definition of a disconnection callback function. More...
 
- Public Types inherited from Ocean::Network::Socket
enum  SocketResult { SR_SUCCEEDED = 0 , SR_FAILED , SR_BUSY , SR_NOT_CONNECTED }
 Definition of individual result values. More...
 
typedef SOCKET SocketId
 Definition of a socket id. More...
 
typedef int SocketId
 Definition of a socket id. More...
 
typedef std::vector< uint8_t > Buffer
 Definition of a vector holding 8 bit values. More...
 

Public Member Functions

virtual bool connect (const Address4 &address, const Port &port, const unsigned int timeout=1000u)
 Connects to a connection-oriented server. More...
 
virtual bool connect (const unsigned int timeout=1000u)
 Reconnects the client by the usage of the most recent address and port. More...
 
virtual bool disconnect ()
 Disconnects the client. More...
 
virtual bool isConnected () const
 Returns whether this client is connected. More...
 
virtual SocketResult send (const void *data, const size_t size)
 Sends data via the established connection. More...
 
SocketResult send (const std::string &message)
 Sets a message via the established connection. More...
 
Address4 receiverAddress () const
 Returns the (remote) receiver address. More...
 
Port receiverPort () const
 Returns the (remote) receiver port. More...
 
void setReceiveCallback (const ReceiveCallback &callback)
 Sets the receive callback function. More...
 
void setDisconnectCallback (const DisconnectCallback &callback)
 Sets the disconnect callback function. More...
 
- Public Member Functions inherited from Ocean::Network::Socket
virtual ~Socket ()
 Destructs a socket object. More...
 
SocketId id () const
 Returns the socket id. More...
 
Address4 address () const
 Returns the own address of this socket. More...
 
Port port () const
 Returns the own port of this socket. More...
 
virtual bool setAddress (const Address4 &address)
 Sets the own address of this socket. More...
 
virtual bool setPort (const Port &port)
 Sets the own port of this socket. More...
 
 operator bool () const
 Returns whether this socket is valid. More...
 

Protected Member Functions

 ConnectionOrientedClient ()
 Creates a new connection oriented client. More...
 
 ~ConnectionOrientedClient () override
 Destructs a connection oriented client. More...
 
bool onScheduler () override
 The scheduler event function. More...
 
virtual size_t onSend (const void *data, const size_t size)
 Internal event function to send data. More...
 
virtual void onReceived (const void *data, const size_t size)
 Internal event function for received data. More...
 
- Protected Member Functions inherited from Ocean::Network::Client
 Client ()
 Creates a new client. More...
 
 ~Client () override
 Destructs a client. More...
 
- Protected Member Functions inherited from Ocean::Network::Socket
 Socket ()
 Creates a new socket object. More...
 
 Socket (const Socket &object)=delete
 Disabled copy constructor. More...
 
bool setBlockingMode (const bool blocking)
 Sets the blocking mode of this socket. More...
 
size_t maximalMessageSize (const size_t defaultSize=65536)
 Returns the maximal message size in bytes. More...
 
bool releaseSocket ()
 Releases the socket. More...
 
Socketoperator= (const Socket &object)=delete
 Disabled copy operator. More...
 

Protected Attributes

Address4 receiverAddress_
 Receiver address. More...
 
Port receiverPort_
 Receiver port. More...
 
ReceiveCallback receiveCallback_
 Receive callback function. More...
 
DisconnectCallback disconnectCallback_
 Disconnect callback function. More...
 
bool isConnected_ = false
 Determines whether a connection is established. More...
 
- Protected Attributes inherited from Ocean::Network::Client
Buffer socketBuffer_
 The socket buffer of this client. More...
 
- Protected Attributes inherited from Ocean::Network::Socket
SocketId socketId_ = invalidSocketId()
 Socket id. More...
 
Lock lock_
 Socket lock. More...
 
NetworkResource networkResource_
 The network resource object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Network::Socket
static constexpr SocketId invalidSocketId ()
 Returns an invalid socket id. More...
 
static bool setBlockingMode (const SocketId socketId, const bool blocking)
 Sets the blocking mode of a socket. More...
 

Detailed Description

This class is the base class for all connection oriented clients.

Member Typedef Documentation

◆ DisconnectCallback

Definition of a disconnection callback function.

◆ ReceiveCallback

typedef Callback<void, const void*, const size_t> Ocean::Network::ConnectionOrientedClient::ReceiveCallback

Definition of a data receive callback function.

The first parameter provides the received data, which must be copied The second parameter provides the size of the received data, in bytes

Constructor & Destructor Documentation

◆ ConnectionOrientedClient()

Ocean::Network::ConnectionOrientedClient::ConnectionOrientedClient ( )
protected

Creates a new connection oriented client.

◆ ~ConnectionOrientedClient()

Ocean::Network::ConnectionOrientedClient::~ConnectionOrientedClient ( )
overrideprotected

Destructs a connection oriented client.

Member Function Documentation

◆ connect() [1/2]

virtual bool Ocean::Network::ConnectionOrientedClient::connect ( const Address4 address,
const Port port,
const unsigned int  timeout = 1000u 
)
virtual

Connects to a connection-oriented server.

Parameters
addressRemote address of the server to connect
portRemote port of the server to connect
timeoutThe timeout in milliseconds, with range [0, infinity)
Returns
True, if succeeded

Reimplemented in Ocean::Network::TCPClient.

◆ connect() [2/2]

virtual bool Ocean::Network::ConnectionOrientedClient::connect ( const unsigned int  timeout = 1000u)
virtual

Reconnects the client by the usage of the most recent address and port.

Parameters
timeoutThe timeout in milliseconds, with range [0, infinity)
Returns
True, if succeeded

Reimplemented in Ocean::Network::TCPClient.

◆ disconnect()

virtual bool Ocean::Network::ConnectionOrientedClient::disconnect ( )
virtual

Disconnects the client.

Returns
True, if the client was connected

Reimplemented in Ocean::Network::TCPClient.

◆ isConnected()

virtual bool Ocean::Network::ConnectionOrientedClient::isConnected ( ) const
virtual

Returns whether this client is connected.

Returns
True, if so

◆ onReceived()

virtual void Ocean::Network::ConnectionOrientedClient::onReceived ( const void *  data,
const size_t  size 
)
protectedvirtual

Internal event function for received data.

Parameters
dataThe data that has been received, must be valid
sizeThe size of the data in bytes, with range [1, infinity)

Reimplemented in Ocean::Network::PackagedTCPClient.

◆ onScheduler()

bool Ocean::Network::ConnectionOrientedClient::onScheduler ( )
overrideprotectedvirtual

The scheduler event function.

Socket::onScheduler().

Reimplemented from Ocean::Network::Socket.

◆ onSend()

virtual size_t Ocean::Network::ConnectionOrientedClient::onSend ( const void *  data,
const size_t  size 
)
protectedvirtual

Internal event function to send data.

Parameters
dataThe data to send, must be valid
sizeThe size of the data in bytes, with range [1, infinity)
Returns
The number of bytes which have been sent, with range [0, size]

Reimplemented in Ocean::Network::PackagedTCPClient.

◆ receiverAddress()

Address4 Ocean::Network::ConnectionOrientedClient::receiverAddress ( ) const
inline

Returns the (remote) receiver address.

Returns
Receiver address

◆ receiverPort()

Port Ocean::Network::ConnectionOrientedClient::receiverPort ( ) const
inline

Returns the (remote) receiver port.

Returns
Receiver port

◆ send() [1/2]

ConnectionOrientedClient::SocketResult Ocean::Network::ConnectionOrientedClient::send ( const std::string &  message)
inline

Sets a message via the established connection.

Parameters
messageThe message to send, must be valid
Returns
SR_SUCCEEDED, if succeeded

◆ send() [2/2]

virtual SocketResult Ocean::Network::ConnectionOrientedClient::send ( const void *  data,
const size_t  size 
)
virtual

Sends data via the established connection.

If the resource is busy SR_FAILED will be returned and the caller needs to send the data later

Parameters
dataThe data to send, can be nullptr if 'size == 0'
sizeThe size of the data to send, in bytes, with range [0, infinity)
Returns
SR_SUCCEEDED, if succeeded

◆ setDisconnectCallback()

void Ocean::Network::ConnectionOrientedClient::setDisconnectCallback ( const DisconnectCallback callback)
inline

Sets the disconnect callback function.

Parameters
callbackThe callback function to set

◆ setReceiveCallback()

void Ocean::Network::ConnectionOrientedClient::setReceiveCallback ( const ReceiveCallback callback)
inline

Sets the receive callback function.

Parameters
callbackThe callback function to set

Field Documentation

◆ disconnectCallback_

DisconnectCallback Ocean::Network::ConnectionOrientedClient::disconnectCallback_
protected

Disconnect callback function.

◆ isConnected_

bool Ocean::Network::ConnectionOrientedClient::isConnected_ = false
protected

Determines whether a connection is established.

◆ receiveCallback_

ReceiveCallback Ocean::Network::ConnectionOrientedClient::receiveCallback_
protected

Receive callback function.

◆ receiverAddress_

Address4 Ocean::Network::ConnectionOrientedClient::receiverAddress_
protected

Receiver address.

◆ receiverPort_

Port Ocean::Network::ConnectionOrientedClient::receiverPort_
protected

Receiver port.


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