TCP: Transmission Control Protocol¶
https://en.m.wikipedia.org/wiki/Transmission_Control_Protocol
Connection API¶
-
enum
tcp
::
TcpConnectionEvent
¶ Values:
-
eTCE_Connected
= 0¶ Occurs after connection establishment.
-
eTCE_Received
¶ Occurs on data receive.
-
eTCE_Sent
¶
-
eTCE_Poll
¶
-
-
typedef Delegate<void(TcpConnection&)>
TcpConnectionDestroyedDelegate
¶
-
NETWORK_DEBUG
¶
-
NETWORK_SEND_BUFFER_SIZE
¶
-
class
TcpConnection
¶ - #include <TcpConnection.h>
Subclassed by FtpDataStream, FtpServerConnection, TcpClient, TcpServer
Public Functions
-
TcpConnection
(bool autoDestruct)¶
-
TcpConnection
(tcp_pcb *connection, bool autoDestruct)¶
-
virtual
~TcpConnection
()¶
-
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.
- Parameters
data
:len
:apiflags
: TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return Value
int
: -1 on error
-
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.
- Parameters
destroyedDelegate
:
-
void
setSslInitHandler
(Ssl::Session::InitDelegate handler) Set the SSL session initialisation callback.
- Parameters
handler
:
-
bool
setSslConnection
(Ssl::Connection *connection)
-
Ssl::Session *
getSsl
() 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
.
-
Client API¶
-
enum
tcpclient
::
TcpClientState
¶ Values:
-
eTCS_Ready
¶
-
eTCS_Connecting
¶
-
eTCS_Connected
¶
-
eTCS_Successful
¶
-
eTCS_Failed
¶
-
-
enum
tcpclient
::
TcpClientCloseAfterSentState
¶ Values:
-
eTCCASS_None
¶
-
eTCCASS_AfterSent
¶
-
eTCCASS_AfterSent_Ignore_Received
¶
-
-
TCP_CLIENT_TIMEOUT
¶
-
class
TcpClient
: public TcpConnection¶ - #include <TcpClient.h>
Subclassed by HttpConnection, MqttClient, SmtpClient
Public 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)
-
bool
connect
(IpAddress addr, uint16_t port, bool useSsl = false)
-
void
close
()
-
void
setReceiveDelegate
(TcpClientDataDelegate receiveCb = nullptr) Set or clear the callback for received data.
- Parameters
receiveCb
: callback delegate or nullptr
-
void
setCompleteDelegate
(TcpClientCompleteDelegate completeCb = nullptr) Set or clear the callback for connection close.
- Parameters
completeCb
: callback delegate or nullptr
-
bool
send
(const char *data, uint16_t len, bool forceCloseAfterSent = false)
-
bool
sendString
(const String &data, bool forceCloseAfterSent = false)
-
bool
isProcessing
()
-
TcpClientState
getConnectionState
()
-
void
setCloseAfterSent
(bool ignoreIncomingData = false) Schedules the connection to get closed after the data is sent
- Parameters
ignoreIncomingData
: when that flag is set the connection will start ignoring incoming data.
-
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.
- Parameters
data
:len
:apiflags
: TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return Value
int
: -1 on error
-
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.
- Parameters
destroyedDelegate
:
-
void
setSslInitHandler
(Ssl::Session::InitDelegate handler) Set the SSL session initialisation callback.
- Parameters
handler
:
-
bool
setSslConnection
(Ssl::Connection *connection)
-
Ssl::Session *
getSsl
() 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
.
-
Server API¶
-
TCP_SERVER_TIMEOUT
¶
-
class
TcpServer
: public TcpConnection¶ - #include <TcpServer.h>
Subclassed by FtpServer, HttpServer, TelnetServer
Public 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.
- Parameters
data
:len
:apiflags
: TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return Value
int
: -1 on error
-
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.
- Parameters
destroyedDelegate
:
-
void
setSslInitHandler
(Ssl::Session::InitDelegate handler) Set the SSL session initialisation callback.
- Parameters
handler
:
-
bool
setSslConnection
(Ssl::Connection *connection)
-
Ssl::Session *
getSsl
() 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
.
Public Members
-
uint16_t
activeClients
= 0
-