1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

tcp client 1st working

This commit is contained in:
wellenvogel
2022-01-02 17:26:46 +01:00
parent d21e497864
commit 5b843a23be
5 changed files with 25 additions and 16 deletions

View File

@@ -8,7 +8,7 @@ bool GwTcpClient::isConnected(){
}
void GwTcpClient::stop()
{
if (connection->hasClient())
if (connection && connection->hasClient())
{
LOG_DEBUG(GwLog::DEBUG, "stopping tcp client");
connection->stop();
@@ -17,7 +17,8 @@ void GwTcpClient::stop()
}
void GwTcpClient::startConnection()
{
//TODO
LOG_DEBUG(GwLog::DEBUG,"TcpClient::startConnection to %s:%d",
remoteAddress.c_str(),port);
state = C_INITIALIZED;
error="";
connectStart=millis();
@@ -50,15 +51,19 @@ void GwTcpClient::startConnection()
}
state=C_CONNECTING;
connection->setClient(sockfd);
LOG_DEBUG(GwLog::DEBUG,"TcpClient connecting...");
}
else{
state=C_CONNECTED;
connection->setClient(sockfd);
LOG_DEBUG(GwLog::DEBUG,"TcpClient connected");
}
}
void GwTcpClient::checkConnection()
{
unsigned long now=millis();
LOG_DEBUG(GwLog::DEBUG+3,"TcpClient::checkConnection state=%d, start=%ul, now=%ul",
(int)state,connectStart,now);
if (! connection->hasClient()){
state = hasConfig()?C_INITIALIZED:C_DISABLED;
}
@@ -118,6 +123,7 @@ void GwTcpClient::checkConnection()
GwTcpClient::GwTcpClient(GwLog *logger)
{
this->logger = logger;
this->connection=NULL;
}
GwTcpClient::~GwTcpClient(){
if (connection)

View File

@@ -3,7 +3,7 @@
#include "GwChannelInterface.h"
class GwTcpClient : public GwChannelInterface
{
static const unsigned long CON_TIMEOUT=10;
static const unsigned long CON_TIMEOUT=10000;
GwSocketConnection *connection = NULL;
String remoteAddress;
uint16_t port = 0;