Ocean
Ocean::Network::TCPClient Class Reference

This class implements a TCP client. More...

Inheritance diagram for Ocean::Network::TCPClient:

Public Member Functions

 TCPClient ()
 Creates a new TCP client. More...
 
 ~TCPClient () override
 Destructs a TCP client. More...
 
bool connect (const Address4 &address, const Port &port, const unsigned int timeout=1000u) override
 Connects to a TCP server. More...
 
bool connect (const unsigned int timeout=1000u) override
 Reconnects the client by the usage of the most recent address and port. More...
 
bool disconnect () override
 Disconnects the client. More...
 
- Public Member Functions inherited from Ocean::Network::ConnectionOrientedClient
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

bool buildSocket ()
 Build the TCP socket. More...
 
- Protected Member Functions inherited from Ocean::Network::ConnectionOrientedClient
 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...
 

Additional Inherited Members

- Public Types inherited from Ocean::Network::ConnectionOrientedClient
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...
 
- 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...
 
- Protected Attributes inherited from Ocean::Network::ConnectionOrientedClient
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...
 

Detailed Description

This class implements a TCP client.

A TCP client can send and receive data to (and from) one remove TCP client.
TCP is a stream-based network protocol which does not provide any message boundaries.

Constructor & Destructor Documentation

◆ TCPClient()

Ocean::Network::TCPClient::TCPClient ( )

Creates a new TCP client.

◆ ~TCPClient()

Ocean::Network::TCPClient::~TCPClient ( )
override

Destructs a TCP client.

Member Function Documentation

◆ buildSocket()

bool Ocean::Network::TCPClient::buildSocket ( )
protected

Build the TCP socket.

Returns
True, if succeeded

◆ connect() [1/2]

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

Connects to a TCP server.

See also
ConnectionOrientedClient::connect().

Reimplemented from Ocean::Network::ConnectionOrientedClient.

◆ connect() [2/2]

bool Ocean::Network::TCPClient::connect ( const unsigned int  timeout = 1000u)
overridevirtual

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

See also
ConnectionOrientedClient::connect().

Reimplemented from Ocean::Network::ConnectionOrientedClient.

◆ disconnect()

bool Ocean::Network::TCPClient::disconnect ( )
overridevirtual

Disconnects the client.

See also
ConnectionOrientedClient::disconnect().

Reimplemented from Ocean::Network::ConnectionOrientedClient.


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