#include <TcpClient.h>

Inheritance diagram for TcpClient:
Collaboration diagram for TcpClient:

Public Member Functions

 TcpClient (bool autoDestruct)
 
 TcpClient (tcp_pcb *clientTcp, TcpClientDataDelegate clientReceive, TcpClientCompleteDelegate onCompleted)
 
 TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientEventDelegate onReadyToSend, TcpClientDataDelegate onReceive=nullptr)
 
 TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientDataDelegate onReceive=nullptr)
 
 TcpClient (TcpClientDataDelegate onReceive)
 
 ~TcpClient ()
 
bool connect (const String &server, int port, bool useSsl=false) override
 
bool connect (IpAddress addr, uint16_t port, bool useSsl=false) override
 
void close () override
 
void setReceiveDelegate (TcpClientDataDelegate receiveCb=nullptr)
 Set or clear the callback for received data. More...
 
void setCompleteDelegate (TcpClientCompleteDelegate completeCb=nullptr)
 Set or clear the callback for connection close. More...
 
bool send (const char *data, uint16_t len, bool forceCloseAfterSent=false)
 
bool sendString (const String &data, bool forceCloseAfterSent=false)
 
bool send (IDataSourceStream *source, bool forceCloseAfterSent=false)
 Sends data stream. More...
 
bool isProcessing ()
 
TcpClientState getConnectionState ()
 
void setCloseAfterSent (bool ignoreIncomingData=false)
 
void commit ()
 Tries to send the pending data immediately. More...
 
- Public Member Functions inherited from TcpConnection
 TcpConnection (bool autoDestruct)
 
 TcpConnection (tcp_pcb *connection, bool autoDestruct)
 
virtual ~TcpConnection ()
 
int writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
int writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
virtual int write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Base write operation. More...
 
int write (IDataSourceStream *stream)
 Writes stream data directly to the TCP buffer. More...
 
uint16_t getAvailableWriteSize ()
 
void flush ()
 
void setTimeOut (uint16_t waitTimeOut)
 
IpAddress getRemoteIp () const
 
uint16_t getRemotePort () const
 
void setDestroyedDelegate (TcpConnectionDestroyedDelegate destroyedDelegate)
 Sets a callback to be called when the object instance is destroyed. More...
 
void setSslInitHandler (Ssl::Session::InitDelegate handler)
 Set the SSL session initialisation callback. More...
 
bool setSslConnection (Ssl::Connection *connection)
 
Ssl::SessiongetSsl ()
 Get a pointer to the current SSL session object. More...
 
- Public Member Functions inherited from IpConnection
bool joinMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to add a local network interface to multicast group. More...
 
bool joinMulticastGroup (IpAddress multicastIp)
 Uses IGMP to add all local network interfaces to multicast group. More...
 
bool leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to remove a local network interface from multicast group. More...
 
bool leaveMulticastGroup (IpAddress multicastIp)
 Uses IGMP to remove all local network interfaces from multicast group. More...
 

Protected Member Functions

err_t onConnected (err_t err) override
 
err_t onReceive (pbuf *buf) override
 
err_t onSent (uint16_t len) override
 
void onError (err_t err) override
 
void onClosed () override
 Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect. More...
 
void onReadyToSendData (TcpConnectionEvent sourceEvent) override
 
virtual void onFinished (TcpClientState finishState)
 
void pushAsyncPart ()
 
void freeStreams ()
 
- Protected Member Functions inherited from TcpConnection
void initialize (tcp_pcb *pcb)
 
bool internalConnect (IpAddress addr, uint16_t port)
 
bool sslCreateSession ()
 
virtual void sslInitSession (Ssl::Session &session)
 Override in inherited classes to perform custom session initialisation. More...
 
virtual err_t onPoll ()
 
void trySend (TcpConnectionEvent event)
 
err_t internalOnConnected (err_t err)
 
err_t internalOnReceive (pbuf *p, err_t err)
 
err_t internalOnSent (uint16_t len)
 
err_t internalOnPoll ()
 
void internalOnError (err_t err)
 
void internalOnDnsResponse (const char *name, LWIP_IP_ADDR_T *ipaddr, int port)
 

Protected Attributes

IDataSourceStreamstream = nullptr
 The currently active stream being sent. More...
 
- Protected Attributes inherited from TcpConnection
tcp_pcb * tcp = nullptr
 
uint16_t sleep = 0
 
uint16_t timeOut = USHRT_MAX
 By default a TCP connection does not have a time out. More...
 
bool canSend = true
 
bool autoSelfDestruct = true
 
Ssl::Sessionssl = nullptr
 
Ssl::Session::InitDelegate sslInit
 
bool useSsl = false
 

Constructor & Destructor Documentation

◆ TcpClient() [1/5]

TcpClient::TcpClient ( bool  autoDestruct)
inline

◆ TcpClient() [2/5]

TcpClient::TcpClient ( tcp_pcb *  clientTcp,
TcpClientDataDelegate  clientReceive,
TcpClientCompleteDelegate  onCompleted 
)
inline

◆ TcpClient() [3/5]

TcpClient::TcpClient ( TcpClientCompleteDelegate  onCompleted,
TcpClientEventDelegate  onReadyToSend,
TcpClientDataDelegate  onReceive = nullptr 
)
inline

◆ TcpClient() [4/5]

TcpClient::TcpClient ( TcpClientCompleteDelegate  onCompleted,
TcpClientDataDelegate  onReceive = nullptr 
)
inline

◆ TcpClient() [5/5]

TcpClient::TcpClient ( TcpClientDataDelegate  onReceive)
inlineexplicit

◆ ~TcpClient()

TcpClient::~TcpClient ( )
inline

Member Function Documentation

◆ close()

void TcpClient::close ( )
overridevirtual

Reimplemented from TcpConnection.

◆ commit()

void TcpClient::commit ( )
inline

Tries to send the pending data immediately.

Note
Call this method to decrease latency. Use it carefully.

◆ connect() [1/2]

bool TcpClient::connect ( const String server,
int  port,
bool  useSsl = false 
)
overridevirtual

Reimplemented from TcpConnection.

◆ connect() [2/2]

bool TcpClient::connect ( IpAddress  addr,
uint16_t  port,
bool  useSsl = false 
)
overridevirtual

Reimplemented from TcpConnection.

◆ freeStreams()

void TcpClient::freeStreams ( )
protected

◆ getConnectionState()

TcpClientState TcpClient::getConnectionState ( )
inline

◆ isProcessing()

bool TcpClient::isProcessing ( )
inline

◆ onClosed()

void TcpClient::onClosed ( )
overrideprotectedvirtual

Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect.

Note
This method can be used to trigger reconnects

Reimplemented from TcpConnection.

◆ onConnected()

err_t TcpClient::onConnected ( err_t  err)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onError()

void TcpClient::onError ( err_t  err)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onFinished()

virtual void TcpClient::onFinished ( TcpClientState  finishState)
protectedvirtual

Reimplemented in MqttClient.

◆ onReadyToSendData()

void TcpClient::onReadyToSendData ( TcpConnectionEvent  sourceEvent)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onReceive()

err_t TcpClient::onReceive ( pbuf *  buf)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ onSent()

err_t TcpClient::onSent ( uint16_t  len)
overrideprotectedvirtual

Reimplemented from TcpConnection.

◆ pushAsyncPart()

void TcpClient::pushAsyncPart ( )
protected

◆ send() [1/2]

bool TcpClient::send ( const char *  data,
uint16_t  len,
bool  forceCloseAfterSent = false 
)

◆ send() [2/2]

bool TcpClient::send ( IDataSourceStream source,
bool  forceCloseAfterSent = false 
)

Sends data stream.

Note
This function takes ownership of the stream pointer!
Parameters
sourcestream pointer
forceCloseAfterSent
Return values
booltrue when the stream can be used. When false the stream will be deleted.

◆ sendString()

bool TcpClient::sendString ( const String data,
bool  forceCloseAfterSent = false 
)
inline

◆ setCloseAfterSent()

void TcpClient::setCloseAfterSent ( bool  ignoreIncomingData = false)
inline

Schedules the connection to get closed after the data is sent

Parameters
ignoreIncomingDatawhen that flag is set the connection will start ignoring incoming data.

◆ setCompleteDelegate()

void TcpClient::setCompleteDelegate ( TcpClientCompleteDelegate  completeCb = nullptr)
inline

Set or clear the callback for connection close.

Parameters
completeCbcallback delegate or nullptr

◆ setReceiveDelegate()

void TcpClient::setReceiveDelegate ( TcpClientDataDelegate  receiveCb = nullptr)
inline

Set or clear the callback for received data.

Parameters
receiveCbcallback delegate or nullptr

Member Data Documentation

◆ stream

IDataSourceStream* TcpClient::stream = nullptr
protected

The currently active stream being sent.


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