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
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

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 Value
  • int: negative on error, 0 when retry is needed or possitive on success

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 Value
  • int: negative on error, 0 when retry is needed or possitive 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 Value
  • int: negative on error, 0 when retry is needed or possitive 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 Value
  • int: negative on error, 0 when retry is needed or possitive on success

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:

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
using TcpClientEventDelegate = Delegate<void(TcpClient &client, TcpConnectionEvent sourceEvent)>
using TcpClientCompleteDelegate = Delegate<void(TcpClient &client, bool successful)>
using TcpClientDataDelegate = Delegate<bool(TcpClient &client, char *data, int size)>
TCP_CLIENT_TIMEOUT
class TcpClient : public TcpConnection
#include <TcpClient.h>

Subclassed by HttpConnection, MqttClient, SmtpClient

Public Functions

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

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.

void commit()

Tries to send the pending data immediately.

Note

Call this method to decrease latency. Use it carefully.

Server API

using TcpClientConnectDelegate = Delegate<void(TcpClient *client)>
TCP_SERVER_TIMEOUT
class TcpServer : public TcpConnection
#include <TcpServer.h>

Subclassed by CustomFtpServer, HttpServer, TelnetServer