TCP: Transmission Control Protocol
https://en.m.wikipedia.org/wiki/Transmission_Control_Protocol
Connection API
-
enum TcpConnectionEvent
Values:
-
enumerator eTCE_Connected
Occurs after connection establishment.
-
enumerator eTCE_Received
Occurs on data receive.
-
enumerator eTCE_Sent
-
enumerator eTCE_Poll
-
enumerator eTCE_Connected
-
using TcpConnectionDestroyedDelegate = Delegate<void(TcpConnection&)>
-
NETWORK_DEBUG
-
NETWORK_SEND_BUFFER_SIZE
-
class TcpConnection : public IpConnection
- #include <TcpConnection.h>
Subclassed by FtpDataStream, FtpServerConnection, TcpClient, TcpServer
Public Functions
-
inline int writeString(const char *data, uint8_t apiflags = TCP_WRITE_FLAG_COPY)
Writes string data directly to the TCP buffer.
- Parameters:
data – null terminated string
apiflags – TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return values:
int – negative on error, 0 when retry is needed or positive on success
-
inline int writeString(const String &data, uint8_t apiflags = TCP_WRITE_FLAG_COPY)
Writes string data directly to the TCP buffer.
- Parameters:
data –
apiflags – TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return values:
int – negative on error, 0 when retry is needed or positive on success
-
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 values:
int – negative on error, 0 when retry is needed or positive on success
-
int write(IDataSourceStream *stream)
Writes stream data directly to the TCP buffer.
- Parameters:
stream –
apiflags – TCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
- Return values:
int – negative on error, 0 when retry is needed or positive on success
-
inline void setDestroyedDelegate(TcpConnectionDestroyedDelegate destroyedDelegate)
Sets a callback to be called when the object instance is destroyed.
- Parameters:
destroyedDelegate –
-
inline void setSslInitHandler(Ssl::Session::InitDelegate handler)
Set the SSL session initialisation callback.
- Parameters:
handler –
-
inline int writeString(const char *data, uint8_t apiflags = TCP_WRITE_FLAG_COPY)
Client API
-
enum TcpClientState
Values:
-
enumerator eTCS_Ready
-
enumerator eTCS_Connecting
-
enumerator eTCS_Connected
-
enumerator eTCS_Successful
-
enumerator eTCS_Failed
-
enumerator eTCS_Ready
-
enum TcpClientCloseAfterSentState
Values:
-
enumerator eTCCASS_None
-
enumerator eTCCASS_AfterSent
-
enumerator eTCCASS_AfterSent_Ignore_Received
-
enumerator eTCCASS_None
-
using TcpClientEventDelegate = Delegate<void(TcpClient &client, TcpConnectionEvent sourceEvent)>
-
TCP_CLIENT_TIMEOUT
-
class TcpClient : public TcpConnection
- #include <TcpClient.h>
Subclassed by HttpConnection, MqttClient, SmtpClient
Public Functions
-
inline void setReceiveDelegate(TcpClientDataDelegate receiveCb = nullptr)
Set or clear the callback for received data.
- Parameters:
receiveCb – callback delegate or nullptr
-
inline void setCompleteDelegate(TcpClientCompleteDelegate completeCb = nullptr)
Set or clear the callback for connection close.
- Parameters:
completeCb – callback delegate or nullptr
-
bool send(IDataSourceStream *source, bool forceCloseAfterSent = false)
Sends data stream.
Note
This function takes ownership of the stream pointer!
- Parameters:
source – stream pointer
forceCloseAfterSent –
- Return values:
bool – true when the stream can be used. When false the stream will be deleted.
-
inline 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.
-
inline void commit()
Tries to send the pending data immediately.
Note
Call this method to decrease latency. Use it carefully.
-
inline void setReceiveDelegate(TcpClientDataDelegate receiveCb = nullptr)
Server API
-
TCP_SERVER_TIMEOUT
-
class TcpServer : public TcpConnection
- #include <TcpServer.h>
Subclassed by CustomFtpServer, HttpServer