#include <TcpServer.h>

Inheritance diagram for TcpServer:
[legend]
Collaboration diagram for TcpServer:
[legend]

Public Member Functions

 TcpServer ()
 
 TcpServer (TcpClientConnectDelegate onClientHandler, TcpClientDataDelegate clientReceiveDataHandler, TcpClientCompleteDelegate clientCompleteHandler)
 
 TcpServer (TcpClientDataDelegate clientReceiveDataHandler, TcpClientCompleteDelegate clientCompleteHandler)
 
 TcpServer (TcpClientDataDelegate clientReceiveDataHandler)
 
 ~TcpServer ()
 
virtual bool listen (int port, bool useSsl=false)
 
void setKeepAlive (uint16_t seconds)
 
void shutdown ()
 
const Vector< TcpConnection * > & getConnections () const
 
virtual bool connect (const String &server, int port, bool useSsl=false)
 
virtual bool connect (IpAddress addr, uint16_t port, bool useSsl=false)
 
virtual void close ()
 
int writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 
int writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 
virtual int write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Base write operation. More...
 
int write (IDataSourceStream *stream)
 
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 Attributes

uint16_t activeClients = 0
 

Protected Member Functions

virtual TcpConnectioncreateClient (tcp_pcb *clientTcp)
 
virtual err_t onAccept (tcp_pcb *clientTcp, err_t err)
 
virtual void onClient (TcpClient *client)
 
virtual bool onClientReceive (TcpClient &client, char *data, int size)
 
virtual void onClientComplete (TcpClient &client, bool successful)
 
virtual void onClientDestroy (TcpConnection &connection)
 
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 onConnected (err_t err)
 
virtual err_t onReceive (pbuf *buf)
 
virtual err_t onSent (uint16_t len)
 
virtual err_t onPoll ()
 
virtual void onError (err_t err)
 
virtual void onReadyToSendData (TcpConnectionEvent sourceEvent)
 
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

size_t minHeapSize = 16384
 
uint16_t maxConnections = 0
 By default, don't limit connection count. More...
 
bool active = true
 
Vector< TcpConnection * > connections
 
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

◆ TcpServer() [1/4]

TcpServer::TcpServer ( )
inline

◆ TcpServer() [2/4]

TcpServer::TcpServer ( TcpClientConnectDelegate  onClientHandler,
TcpClientDataDelegate  clientReceiveDataHandler,
TcpClientCompleteDelegate  clientCompleteHandler 
)
inline

◆ TcpServer() [3/4]

TcpServer::TcpServer ( TcpClientDataDelegate  clientReceiveDataHandler,
TcpClientCompleteDelegate  clientCompleteHandler 
)
inline

◆ TcpServer() [4/4]

TcpServer::TcpServer ( TcpClientDataDelegate  clientReceiveDataHandler)
inline

◆ ~TcpServer()

TcpServer::~TcpServer ( )
inline

Member Function Documentation

◆ close()

virtual void TcpConnection::close ( )
virtualinherited

Reimplemented in TcpClient.

◆ connect() [1/2]

virtual bool TcpConnection::connect ( const String server,
int  port,
bool  useSsl = false 
)
virtualinherited

Reimplemented in TcpClient, and HttpClientConnection.

◆ connect() [2/2]

virtual bool TcpConnection::connect ( IpAddress  addr,
uint16_t  port,
bool  useSsl = false 
)
virtualinherited

Reimplemented in TcpClient.

◆ createClient()

virtual TcpConnection* TcpServer::createClient ( tcp_pcb *  clientTcp)
protectedvirtual

Reimplemented in HttpServer, and FtpServer.

◆ flush()

void TcpConnection::flush ( )
inherited

◆ getAvailableWriteSize()

uint16_t TcpConnection::getAvailableWriteSize ( )
inlineinherited

◆ getConnections()

const Vector<TcpConnection*>& TcpServer::getConnections ( ) const
inline

◆ getRemoteIp()

IpAddress TcpConnection::getRemoteIp ( ) const
inlineinherited

◆ getRemotePort()

uint16_t TcpConnection::getRemotePort ( ) const
inlineinherited

◆ getSsl()

Ssl::Session* TcpConnection::getSsl ( )
inlineinherited

Get a pointer to the current SSL session object.

Note that this is typically used so we can query properties of an established session. If you need to change session parameters this must be done via setSslInitHandler.

◆ initialize()

void TcpConnection::initialize ( tcp_pcb *  pcb)
protectedinherited

◆ internalConnect()

bool TcpConnection::internalConnect ( IpAddress  addr,
uint16_t  port 
)
protectedinherited

◆ internalOnConnected()

err_t TcpConnection::internalOnConnected ( err_t  err)
protectedinherited

◆ internalOnDnsResponse()

void TcpConnection::internalOnDnsResponse ( const char *  name,
LWIP_IP_ADDR_T ipaddr,
int  port 
)
protectedinherited

◆ internalOnError()

void TcpConnection::internalOnError ( err_t  err)
protectedinherited

◆ internalOnPoll()

err_t TcpConnection::internalOnPoll ( )
protectedinherited

◆ internalOnReceive()

err_t TcpConnection::internalOnReceive ( pbuf *  p,
err_t  err 
)
protectedinherited

◆ internalOnSent()

err_t TcpConnection::internalOnSent ( uint16_t  len)
protectedinherited

◆ listen()

virtual bool TcpServer::listen ( int  port,
bool  useSsl = false 
)
virtual

◆ onAccept()

virtual err_t TcpServer::onAccept ( tcp_pcb *  clientTcp,
err_t  err 
)
protectedvirtual

◆ onClient()

virtual void TcpServer::onClient ( TcpClient client)
protectedvirtual

◆ onClientComplete()

virtual void TcpServer::onClientComplete ( TcpClient client,
bool  successful 
)
protectedvirtual

◆ onClientDestroy()

virtual void TcpServer::onClientDestroy ( TcpConnection connection)
protectedvirtual

◆ onClientReceive()

virtual bool TcpServer::onClientReceive ( TcpClient client,
char *  data,
int  size 
)
protectedvirtual

◆ onConnected()

virtual err_t TcpConnection::onConnected ( err_t  err)
protectedvirtualinherited

Reimplemented in TcpClient, and FtpDataStream.

◆ onError()

virtual void TcpConnection::onError ( err_t  err)
protectedvirtualinherited

Reimplemented in HttpConnection, and TcpClient.

◆ onPoll()

virtual err_t TcpConnection::onPoll ( )
protectedvirtualinherited

◆ onReadyToSendData()

virtual void TcpConnection::onReadyToSendData ( TcpConnectionEvent  sourceEvent)
protectedvirtualinherited

◆ onReceive()

virtual err_t TcpConnection::onReceive ( pbuf *  buf)
protectedvirtualinherited

◆ onSent()

virtual err_t TcpConnection::onSent ( uint16_t  len)
protectedvirtualinherited

Reimplemented in TcpClient, FtpServerConnection, and FtpDataStream.

◆ setDestroyedDelegate()

void TcpConnection::setDestroyedDelegate ( TcpConnectionDestroyedDelegate  destroyedDelegate)
inlineinherited

Sets a callback to be called when the object instance is destroyed.

Parameters
destroyedDelegate

◆ setKeepAlive()

void TcpServer::setKeepAlive ( uint16_t  seconds)

◆ setSslConnection()

bool TcpConnection::setSslConnection ( Ssl::Connection connection)
inlineinherited

◆ setSslInitHandler()

void TcpConnection::setSslInitHandler ( Ssl::Session::InitDelegate  handler)
inlineinherited

Set the SSL session initialisation callback.

Parameters
handler

◆ setTimeOut()

void TcpConnection::setTimeOut ( uint16_t  waitTimeOut)
inherited

◆ shutdown()

void TcpServer::shutdown ( )

◆ sslCreateSession()

bool TcpConnection::sslCreateSession ( )
protectedinherited

◆ sslInitSession()

virtual void TcpConnection::sslInitSession ( Ssl::Session session)
inlineprotectedvirtualinherited

Override in inherited classes to perform custom session initialisation.

Called when TCP connection is established before initiating handshake.

Reimplemented in HttpClientConnection.

◆ trySend()

void TcpConnection::trySend ( TcpConnectionEvent  event)
inlineprotectedinherited

◆ write() [1/2]

virtual int TcpConnection::write ( const char *  data,
int  len,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
virtualinherited

Base write operation.

Parameters
data
len
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
int-1 on error

Reimplemented in FtpDataStream.

◆ write() [2/2]

int TcpConnection::write ( IDataSourceStream stream)
inherited

◆ writeString() [1/2]

int TcpConnection::writeString ( const char *  data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inlineinherited

◆ writeString() [2/2]

int TcpConnection::writeString ( const String data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inlineinherited

Member Data Documentation

◆ active

bool TcpServer::active = true
protected

◆ activeClients

uint16_t TcpServer::activeClients = 0

◆ autoSelfDestruct

bool TcpConnection::autoSelfDestruct = true
protectedinherited

◆ canSend

bool TcpConnection::canSend = true
protectedinherited

◆ connections

Vector<TcpConnection*> TcpServer::connections
protected

◆ maxConnections

uint16_t TcpServer::maxConnections = 0
protected

By default, don't limit connection count.

◆ minHeapSize

size_t TcpServer::minHeapSize = 16384
protected

◆ sleep

uint16_t TcpConnection::sleep = 0
protectedinherited

◆ ssl

Ssl::Session* TcpConnection::ssl = nullptr
protectedinherited

◆ sslInit

Ssl::Session::InitDelegate TcpConnection::sslInit
protectedinherited

◆ tcp

tcp_pcb* TcpConnection::tcp = nullptr
protectedinherited

◆ timeOut

uint16_t TcpConnection::timeOut = USHRT_MAX
protectedinherited

By default a TCP connection does not have a time out.

◆ useSsl

bool TcpConnection::useSsl = false
protectedinherited

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