---
title: "STM32F103 W5500 TCP Server"
url: "https://maker.wiznet.io/mark/projects/stm32f103-w5500-tcp-server-1/"
markdown_url: "https://maker.wiznet.io/mark/projects/stm32f103-w5500-tcp-server-1/md"
type: "UCC: User Created Content"
author: "donglicaiju76152"
author_url: "https://blog.csdn.net/donglicaiju76152/article/details/95735091?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165565689716781435418275%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165565689716781435418275&"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "donglicaiju76152"
original_url: "https://blog.csdn.net/donglicaiju76152/article/details/95735091?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165565689716781435418275%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165565689716781435418275&"
published: "2023-02-28"
language: "en"
likes: 2
views: 177
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# STM32F103 W5500 TCP Server

> STM32F103 W5500 TCP Server

Original author: donglicaiju76152 (source: https://blog.csdn.net/donglicaiju76152/article/details/95735091?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165565689716781435418275%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165565689716781435418275&)

## Article

History: Use STM32F4+LWIP before, but BOM cost too high and not user friendly for LWIP. Finally choose W5500.

3 TCP Client Socket setting:

![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597730%2Epng)

![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597738%2Epng)

![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597747%2Epng)

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.

•Add spare socket:

If there are three clients, then open six clients. Each client has one for normal use and one for backup.

•Heartbeat processing

The automatic sending of heartbeats is changed to manual sending.

•Increase delay

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.

![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597798%2Epng)

Remove auto send Keep Alive packet

![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597817%2Epng)

Add a spare socket. The standby socket is always in the listen state.
![](https://maker.wiznet.io/upload/ckeditor5/691904766%5F1677597845%2Epng)

Manually send keepalive heartbeat packets every 10s.

---

Source: https://maker.wiznet.io/mark/projects/stm32f103-w5500-tcp-server-1/
