|
Ocean
|
This class is the base class for all connection oriented clients. More...
#include <ConnectionOrientedClient.h>
Public Types | |
| using | ReceiveCallback = Callback< void, const void *, const size_t > |
| Definition of a data receive callback function. | |
| using | DisconnectCallback = Callback< void > |
| Definition of a disconnection callback function. | |
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... | |
| using | SocketId = SOCKET |
| Definition of a socket id. | |
| using | SocketId = int |
| Definition of a socket id. | |
| using | Buffer = std::vector< uint8_t > |
| Definition of a vector holding 8 bit values. | |
Public Member Functions | |
| virtual bool | connect (const Address4 &address, const Port &port, const unsigned int timeout=1000u) |
| Connects to a connection-oriented server. | |
| virtual bool | connect (const unsigned int timeout=1000u) |
| Reconnects the client by the usage of the most recent address and port. | |
| virtual bool | disconnect () |
| Disconnects the client. | |
| virtual bool | isConnected () const |
| Returns whether this client is connected. | |
| virtual SocketResult | send (const void *data, const size_t size) |
| Sends data via the established connection. | |
| SocketResult | send (const std::string &message) |
| Sets a message via the established connection. | |
| Address4 | receiverAddress () const |
| Returns the (remote) receiver address. | |
| Port | receiverPort () const |
| Returns the (remote) receiver port. | |
| void | setReceiveCallback (const ReceiveCallback &callback) |
| Sets the receive callback function. | |
| void | setDisconnectCallback (const DisconnectCallback &callback) |
| Sets the disconnect callback function. | |
Public Member Functions inherited from Ocean::Network::Socket | |
| virtual | ~Socket () |
| Destructs a socket object. | |
| SocketId | id () const |
| Returns the socket id. | |
| Address4 | address () const |
| Returns the own address of this socket. | |
| Port | port () const |
| Returns the own port of this socket. | |
| virtual bool | setAddress (const Address4 &address) |
| Sets the own address of this socket. | |
| virtual bool | setPort (const Port &port) |
| Sets the own port of this socket. | |
| operator bool () const | |
| Returns whether this socket is valid. | |
Protected Member Functions | |
| ConnectionOrientedClient () | |
| Creates a new connection oriented client. | |
| ~ConnectionOrientedClient () override | |
| Destructs a connection oriented client. | |
| bool | onScheduler () override |
| The scheduler event function. | |
| virtual size_t | onSend (const void *data, const size_t size) |
| Internal event function to send data. | |
| virtual void | onReceived (const void *data, const size_t size) |
| Internal event function for received data. | |
Protected Member Functions inherited from Ocean::Network::Client | |
| Client () | |
| Creates a new client. | |
| ~Client () override | |
| Destructs a client. | |
Protected Member Functions inherited from Ocean::Network::Socket | |
| Socket () | |
| Creates a new socket object. | |
| Socket (const Socket &object)=delete | |
| Disabled copy constructor. | |
| bool | setBlockingMode (const bool blocking) |
| Sets the blocking mode of this socket. | |
| size_t | maximalMessageSize (const size_t defaultSize=65536) |
| Returns the maximal message size in bytes. | |
| bool | releaseSocket () |
| Releases the socket. | |
| Socket & | operator= (const Socket &object)=delete |
| Disabled copy operator. | |
Protected Attributes | |
| Address4 | receiverAddress_ |
| Receiver address. | |
| Port | receiverPort_ |
| Receiver port. | |
| ReceiveCallback | receiveCallback_ |
| Receive callback function. | |
| DisconnectCallback | disconnectCallback_ |
| Disconnect callback function. | |
| bool | isConnected_ = false |
| Determines whether a connection is established. | |
Protected Attributes inherited from Ocean::Network::Client | |
| Buffer | socketBuffer_ |
| The socket buffer of this client. | |
Protected Attributes inherited from Ocean::Network::Socket | |
| SocketId | socketId_ = invalidSocketId() |
| Socket id. | |
| Lock | lock_ |
| Socket lock. | |
| NetworkResource | networkResource_ |
| The network resource object. | |
Additional Inherited Members | |
Static Public Member Functions inherited from Ocean::Network::Socket | |
| static constexpr SocketId | invalidSocketId () |
| Returns an invalid socket id. | |
| static bool | setBlockingMode (const SocketId socketId, const bool blocking) |
| Sets the blocking mode of a socket. | |
This class is the base class for all connection oriented clients.
Definition of a disconnection callback function.
| using Ocean::Network::ConnectionOrientedClient::ReceiveCallback = Callback<void, const void*, const size_t> |
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
|
protected |
Creates a new connection oriented client.
|
overrideprotected |
Destructs a connection oriented client.
|
virtual |
Connects to a connection-oriented server.
| address | Remote address of the server to connect |
| port | Remote port of the server to connect |
| timeout | The timeout in milliseconds, with range [0, infinity) |
Reimplemented in Ocean::Network::TCPClient.
|
virtual |
Reconnects the client by the usage of the most recent address and port.
| timeout | The timeout in milliseconds, with range [0, infinity) |
Reimplemented in Ocean::Network::TCPClient.
|
virtual |
Disconnects the client.
Reimplemented in Ocean::Network::TCPClient.
|
virtual |
Returns whether this client is connected.
|
protectedvirtual |
Internal event function for received data.
| data | The data that has been received, must be valid |
| size | The size of the data in bytes, with range [1, infinity) |
Reimplemented in Ocean::Network::PackagedTCPClient.
|
overrideprotectedvirtual |
|
protectedvirtual |
Internal event function to send data.
| data | The data to send, must be valid |
| size | The size of the data in bytes, with range [1, infinity) |
Reimplemented in Ocean::Network::PackagedTCPClient.
|
inline |
Returns the (remote) receiver address.
|
inline |
Returns the (remote) receiver port.
|
inline |
Sets a message via the established connection.
| message | The message to send, must be valid |
|
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
| data | The data to send, can be nullptr if 'size == 0' |
| size | The size of the data to send, in bytes, with range [0, infinity) |
|
inline |
Sets the disconnect callback function.
| callback | The callback function to set |
|
inline |
Sets the receive callback function.
| callback | The callback function to set |
|
protected |
Disconnect callback function.
|
protected |
Determines whether a connection is established.
|
protected |
Receive callback function.
|
protected |
Receiver address.
|
protected |
Receiver port.