---
title: "Writing a Simple TCP ECHO Server for W5500+STM32"
url: "https://maker.wiznet.io/scarlet/projects/writing-a-simple-tcp-echo-server-for-w5500-stm32/"
markdown_url: "https://maker.wiznet.io/scarlet/projects/writing-a-simple-tcp-echo-server-for-w5500-stm32/md"
type: "UCC: User Created Content"
author: "eXtreme Electronics"
author_url: "https://www.youtube.com/watch?v=Ka6YYBDQAN8"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "eXtreme Electronics"
original_url: "https://www.youtube.com/watch?v=Ka6YYBDQAN8"
published: "2023-07-31"
language: "en"
likes: 1
views: 303
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Writing a Simple TCP ECHO Server for W5500+STM32

> In last lessons we created a TCP client. Now we will create a TCP server. We will start with an ECHO Server.

Original author: eXtreme Electronics (source: https://www.youtube.com/watch?v=Ka6YYBDQAN8)

## Article

[00:01](https://www.youtube.com/watch?v=undefined&t=1s)

writing a TCP Eco server in the last lesson we created a TCP client now we will create a TCP server we will start with an Eco server an Eco server waits for a client to connect when a client is connected it waits from some data from the client and when it receives those data it sends them back to the client that is why it is called an Eco server the client will be able to observe that Eco is coming from the server and this will teach you important concept related to server programming so now let us begin first I will start my terminal

[00:50](https://www.youtube.com/watch?v=undefined&t=50s)

application here I am using real term and I will use it to view the outputs coming from the serial Port of stm32 for this example that is the TCP server example I will increase the display size for that I will go to the display section I will increase the number of rows and I will change it from 16 to 32 this will make the display bigger and then I will go to the port section and select the specific bow rate and my com port and then I will open the com Port the virtual com port now my terminal application is ready to

[01:33](https://www.youtube.com/watch?v=undefined&t=93s)

view the outputs and then I will start Hercules this time I will go to the TCP client section because my stm32 is working as a server so I will use Hercules as a TCP client and here I will feed the IP address of my embedded host that is my stm32 and it is 192.168.2.112 and since my application my example is listing on Port 5000 I will use port 5000 here then I will power up my stm32 like this and the outputs will appear here and these are the standard outputs we have already discussed them in the previous lessons

[02:22](https://www.youtube.com/watch?v=undefined&t=142s)

and after this line our actual output start that those are related to the TCP server example so here we can see that uh it is initializing the server socket then server socket created successfully and our application is listening on Port 5000 that is why I will use for 5000 here to connect and it is waiting for a client to connect so here is our client I will issue the connect command and you just keep your eye here on the outputs what happens when I click connect here a message is displayed a client connected and now it is waiting for some

[02:59](https://www.youtube.com/watch?v=undefined&t=179s)

client data and here we can also see that it is connected to our embedded host that is scm32 it is successfully connected to this IP address that is 192.168.2.112 and now we can send some data from here from our Hercules client to our embedded Host this is embedded server and let us see what happens now first I will send this text from here I will hit I will put some text here and then I will hit the send button and you just keep your eye here on the outputs so see here what it is telling that it is it has received 17 bytes of data from

[03:36](https://www.youtube.com/watch?v=undefined&t=216s)

the client and data received and what is the data content so here you can see the content of the data whatever data we sent here it is showing here so we can see that the data is successfully received on our stm32 and uh what it is doing after that it is sending the Eco back and here it is also displaying the status that Eco sent back to the client and we can also confirm it here so this pink text this is what we sent to the server and this black text this is what received from our uh This Server so this is the Eco and the Eco is

[04:11](https://www.youtube.com/watch?v=undefined&t=251s)

enclosed within this square bracket so you can send several messages and see whether the echo is coming or not uh just keep your eye here so we can see that Eco is coming and now after that we have a special command when we want this Loop to break the loop which is running inside the microcontroller and what it is doing it is waiting for data it is waiting for data from the uh this client so if we want to break the rule if we want to break the loop we have to send a special command and I've created this special

[04:42](https://www.youtube.com/watch?v=undefined&t=282s)

command and this is quit command q u i t quit and when I send this quit message to the this our server see what's happened uh keep your eye here so now I will send a quit command so here you can see uh just after this here received four byte from the client and these four bytes are for this command Q uit This is four white and it has all already this e-code this also this squid command so here you can see uh this quit is sent by our client and this is uh replied by our server so here it is equal sent back to client

[05:22](https://www.youtube.com/watch?v=undefined&t=322s)

and uh just see what is happening after that so it is telling that it has received quit command from the client and so it is disconnecting and then it prints session over and then once again it start to listen on the same port uh because the server should indefinitely infinitely it should await for new and new correction it should not uh so after one connection is over here connection is over it is again initializing the socket and it is again listening on Port 5000 so this is what we are going to code in this lesson hope you will enjoy

[05:54](https://www.youtube.com/watch?v=undefined&t=354s)

it a lot so let us begin so let us go to the coding the complete code of this TCP Eco server is available on udemy.com on my course on w5500 and embedded ethernet just go to udemy.com and search for w5500 like this this one thanks for watching see you in the next lesson

---

Source: https://maker.wiznet.io/scarlet/projects/writing-a-simple-tcp-echo-server-for-w5500-stm32/
