I am using ESP8266 with the SMING framework.
I found this sample code in the Telnet_TCPServer_TCPClient example.
bool tcpServerClientReceive (TcpClient& client, char *data, int size)
{
debugf("Application DataCallback : %s, %d bytes \r\n", client.getRemoteIp().toString().c_str(),size );
debugf("Data : %s", data);
client.sendString("sendString data\r\n", false);
client.writeString("writeString data\r\n",0 );
if (strcmp(data,"close") == 0)
{
debugf("Closing client");
client.close();
};
return true;
}
What is the difference between sendString()
and writeString()
in this sample code? It seems like there is no difference. The outcome is to send string data over to the other TCP party.
The client object used in the example is an instance of TcpClient
which in turns is a derived class from TcpConnection
object. TcpClient
does have a .sendString
method and the .writeString
method is a method of the class TcpConnection
(the parent class of TcpClient
)
In fact there are two overloaded methods for .writeString
So, having all that information out of the way, basically .sendString
does this (inside that method it calls the .send
method):
if (state != eTCS_Connecting && state != eTCS_Connected) return false;
if (stream == NULL)
stream = new MemoryDataStream();
stream->write((const uint8_t*)data, len);
asyncTotalLen += len;
asyncCloseAfterSent = forceCloseAfterSent;
return true;
and the .write
method does this:
u16_t available = getAvailableWriteSize();
if (available < len)
{
if (available == 0)
return -1; // No memory
else
len = available;
}
WDT.alive();
err_t err = tcp_write(tcp, data, len, apiflags);
if (err == ERR_OK)
{
//debugf("TCP connection send: %d (%d)", len, original);
return len;
} else {
//debugf("TCP connection failed with err %d (\"%s\")", err, lwip_strerr(err));
return -1;
}
So from the looks of it one will be async (.sendString
) and the other won't (.writeString
).