My TCP connection do not close

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

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

  2. filter your peer ip & tcp
    ip.addr== peer ip && tcp

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

Thank you

Thanks @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).

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