cancel
Showing results for 
Search instead for 
Did you mean: 

tcp-client implementation

dis_stv
Associate

Need help.
I have a problem with the implementation of the tcp-client. I use STM32H7, FreeRTOS, LWIP (netconn). As a tcp- server - the Hercules terminal.
Situation 1. The tcp-server (Hercules) is waiting for a connection. The tcp-client starts. The connection is made without problems (then you can exchange data, etc.).
Situation 2. the tcp-server is not ready to connect (the Connect button in the terminal is not pressed). The tcp-client tries to connect to the server (sends SYN), but does not receive a response from it (SYN ACK).
The client task is blocked waiting for a response (netconn_connect() function). But the response, even if the server is put into the Connect state, will never arrive (because the server has not actually received the SYN yet). The process is blocked because in the waiting state the client cannot send a new SYN packet and the timeout for the netconn_connect() function cannot be set.
To unblock the process, I use a FreeRTOS timer that I start before calling netconn_connect(). The timer callback function removes the pbuf buffer, closes and deletes the connection, and deletes the current tcp-client task. Then, after a few seconds of delay, the tcp-client task is re-created in the default task. In it, the connection structure is created again and the attempt to connect to the server (with a new src port) is repeated. If at this moment the server is already active, then the connection is created. But there is a problem. During further data exchange, the processor goes into HardFault. With the help of Wireshark, I found out that the device tries to work both with a new, just created, connection, and with an old, previously deleted one (packets are sent both from the old and from the new src port).
It is possible that the data formed for the old connection remains in some buffer. I don't know how to remove them.
Can anyone suggest a solution? Maybe there is another way to create a tcp client that waits for a connection to the server?

0 REPLIES 0