---
title: "My TCP connection do not close"
url: "https://maker.wiznet.io/forum/13560"
markdown_url: "https://maker.wiznet.io/forum/13560/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "electrosaeed"
created: "2019-11-03T14:54:01+09:00"
last_activity: "2019-11-07T01:39:47+09:00"
language: "en"
views: 1182
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# My TCP connection do not close

## Question

Asked by electrosaeed on 2019-11-03 in Ethernet Chips.

I’m using W5500 on my designed board, everything is OK, I have dual simultaneously connection, in one my board (contain W5500) is server and in another it is client.
In client mode I use these functions (like Wiznet samples) (simplified codes):

- socket(sn, Sn_MR_TCP, destport, 0x00) → OK

- connect(sn, destip, destport) → OK

- send(sn, buf, size) → OK

- close(sn) / disconnect(sn) → OK

everything is OK and data is sent to server, but my TCP connection do not close after close or disconnect command. Instead it will close in next data sending in “connect” function, exactly after executing this line:

setSn_CR(sn,Sn_CR_CONNECT);

in one second previous connection closes and new one creating.
I did many things (for ex. re-run close functions in a loop several times), but as my terminal (Hercules) and Windows task manager (TCP connections) said it stay connected until next connect command.

![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/a/a0404c42d27b3f04921db2a00fd824a26d72dff6.png)

## Replies

### Reply 1 by lawrence, 2019-11-03

Hi, electrosaeed

Can you check one more with wireshark?
This is open s/w for check all internet packet.
<https://www.wireshark.org/download.html>

I tried to make the same case with you but could not.

After install the wireshark, please follow below simple guide.

1. select your internet adapter
   [![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/f/f62b0fcdde8cb158e7367a055d25dd1559e39e4e.png) image1464×944 56.9 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/f/f62b0fcdde8cb158e7367a055d25dd1559e39e4e.png)

2. filter your peer ip & tcp
   ip.addr== peer ip && tcp
   [![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/6/67a8eb3c42f4a1cccf7813416762c58984dac906.png) image1464×317 55.1 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/6/67a8eb3c42f4a1cccf7813416762c58984dac906.png)

Could you try again with the close command weather there are FIN packet or not ?

Thank you

### Reply 2 by electrosaeed, 2019-11-04

Thanks [@lawrence](https://maker.wiznet.io/u/lawrence), I found the problem as follows:

When I use “close” command for closing TCP connection, the connection really closes but the server side do not figure it out (not only my app, even windows do not know). So when I try to make new connection using “connect” the server suddenly knows closing and opening connection in same time, so my app (using C# async) think that the connection is closed and throw an exception.
When I changed the command from “close” to “disconnect” it let server to know that the connection is closed so the problem solved (before I was used “disconnect” command after “close” command so it does not work correctly).

### Reply 3 by lawrence, 2019-11-07 (in reply to reply 2)

You made it !!
Right, close command forces tcp connection close. that is why pc or app does not close normally.
Thank you for reply!

---

Source: https://maker.wiznet.io/forum/13560
