Hi everyone,
I am using Lwip 2.1.2 with FreeRtos v10.0.0 and the Netconn API.
I am trying to find a way to gracefully close a Netconn connection and try to reconnect in case of a communication issue.
So, for now I try to do a netconn_write() and in case this method returns an error I try to netconn_close() and netconn_delete() the netconn connection.
To simulate a TCP connection I use Netcat in Linux (Running on my host PC) and my Embedded Device is connected with an Ethernet cable to my PC.
By the time I have a connection and receive data on the PC, I try to simulate a communication interruption by just killing the Netcat connection (Ctrl+c). However, I get the following errors:
netconn_close(netconn) return error: -11 (ERR_CONN = Not connected)
netconn_delete(netconn) returns error: -5 (ERR_INPROGRESS = Operation in progress)
A simplified version of my code:
netconn* tcpListenNetconn;
netconn*
connection;
tcpListenNetconn = netconn_new(NETCONN_TCP);
netconn_bind(tcpListenNetconn, IP4_ADDR_ANY, TCP_PORT);
netconn_listen(tcpListenNetconn);
netconn_accept(tcpListenNetconn, &connection);
uint8_t buffer = 0x65;
while(1)
{
err_t error = netconn_write(connection , &buffer , 1, NETCONN_COPY);
if (error != ERR_OK)
{
netconn_close(connection);
netconn_delete(connection);
break;
}
}