STM32F103 W5500 TCP Server
STM32F103 W5500 TCP Server
2
Project description
History: Use STM32F4+LWIP before, but BOM cost too high and not user friendly for LWIP. Finally choose W5500.
3 TCP Client Socket setting:



Problem:
Three TCP Client can be connected successful when testing. However, during the long-term test of the device, it is found that the connection between the client and the server is often disconnected. Once it is disconnected, some clients can connect, and some clients can no longer connect. The only solution is to restart the device.
The client has a reconnection mechanism, which periodically sends heartbeat packets to the server, and then reconnects to the server after a timeout. There is no problem with the whole mechanism, but the problem is that it still cannot connect to the server.
Solution
First, use the network debugging assistant to simulate the client, and run it for a long time to see if it will be broken, and it has not been broken. Capture packets through wireshark and find that there is no keepalive heartbeat packet.
If there are three clients, then open six clients. Each client has one for normal use and one for backup.
The automatic sending of heartbeats is changed to manual sending.
The information packages on the official website are all demo programs based on bare metal, and this project is multi-threaded, so it needs to be modified to delay in the waiting place.

Remove auto send Keep Alive packet

Add a spare socket. The standby socket is always in the listen state.
![]()
Manually send keepalive heartbeat packets every 10s.