---
title: "sent RST after got FIN"
url: "https://maker.wiznet.io/forum/13845"
markdown_url: "https://maker.wiznet.io/forum/13845/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "huangda1982"
created: "2020-05-22T01:04:51+09:00"
last_activity: "2020-05-25T08:14:12+09:00"
language: "en"
views: 680
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# sent RST after got FIN

## Question

Asked by huangda1982 on 2020-05-22 in Ethernet Chips.

・What am I doing:
A TCP server and A UDP “server” simultaneously

・What I have done in my code:
when I want to close the TCP socket or got a FIN
if the socket status is SOCK_ESTABLISHED then
DICONN
otherwise
CLOSE

・What happend:
got FIN
sent ACK
sent RST

・Then I changed my code as this:
when I want to close the TCP socket or got FIN
if the socket status is SOCK_LISTEN then
CLOSE
if the socket status is SOCK_ESTABLISHED or SOCK_CLOSE_WAIT then
DICONN

・What happend then:
got FIN
sent ACK, FIN
got ACK
sent RST

What am I asking:
What shold I do when I want to close the TCP socket or got a FIN?
For some reason I can not reconstruct the code.
Only this one function I can touch.

・Further question:
①Are these the all status that available in TCP server?
SOCK_INIT
SOCK_LISTEN
SOCK_ESTABLISHED
SOCK_CLOSE_WAIT
SOCK_SYNSENT
SOCK_SYNRECV
SOCK_FIN_WAIT
SOCK_FIN_WAIT
SOCK_CLOSING
SOCK_TIME_WAIT
SOCK_LAST_ACK
SOCK_ARP_0
SOCK_ARP_1
SOCK_ARP_2
②Is the SOCK_CLOSE_WAIT the only available status when got a FIN?
③When I want to close the TCP socket, what should I do when the the CHIP is in each status in ①?

④Are these the all status that available in UDP “server”?
SOCK_INIT
SOCK_UDP
SOCK_ARP_0
SOCK_ARP_1
SOCK_ARP_2
⑤When I want to close the UDP socket, what should I do when the the CHIP is in each status in ④?

Thank you.

## Replies

### Reply 1 by becky, 2020-05-25

1. The status to be managed while using the tcp server is as follows.
   This is because the rest of the status is a brief moment or does not occur on the TCP server.
   [![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/2/2fa2b53ebe2dff2e5147aadbbc83de17e5ef3efb.png) image754×690 203 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/2/2fa2b53ebe2dff2e5147aadbbc83de17e5ef3efb.png)

2. Yes, when FIN is received, W5100 becomes SOCK_CLOSE_WAIT state.

3. Transmit DISCONNECT or CLOSE Command.
   CLOSE is recommended for INIT and LISTEN, CLOSE or DISCONNECT for ESTABLISHED, and DISCONNECT for CLOSE_WAIT.

4. Like the tcp server, the status to be managed while using the udp is as follows.
   [![image](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/c/c2058aac3ac8b7a265e6ba9e055ee0e32194d7ea.png) image686×585 191 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/c/c2058aac3ac8b7a265e6ba9e055ee0e32194d7ea.png)

5. Please send a close command

### Reply 2 by huangda1982, 2020-05-25 (in reply to reply 1)

Thank you for your reply.

Is that possible I get these “brief moment” status when I read Sn_SR, or they are hide from users?

### Reply 3 by becky, 2020-05-25

That is possible.

---

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