---
title: "Disconnect() does not return TIMEOUT error"
url: "https://maker.wiznet.io/forum/10896"
markdown_url: "https://maker.wiznet.io/forum/10896/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "avivf"
created: "2015-03-11T13:11:54+09:00"
last_activity: "2017-05-04T08:35:18+09:00"
language: "en"
views: 1372
replies: 4
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Disconnect() does not return TIMEOUT error

## Question

Asked by avivf on 2015-03-11 in Ethernet Chips.

Hello.

Consider the following scenario:

1. TCP, client vs server

2. client sends disconnect to server (FIN)

3. server replies with ACK

---

## till here it OK

1. server is stuck for some reason (simulated by a breakpoint in the server app)

2. server does not send FIN to client (as supposed)

3. client never changes its socket to close (as it hasn’t received a FIN from the server)

4. client’s socket is in FIN_WAIT (= 0x18) state

5. client is stuck in an infinite loop in the disconnect() func
   |
   |
   V

Can you please help fixing the bug?

Thanks,
Aviv

## Replies

### Reply 1 by avivf, 2015-04-01

Hello,
I’ve been reading your reply. You mentioned that in a server application it’s better to use close() rather than disconnect().

1. What if my application in a client instead of a server. Should I still use close() rather than disconnet()?

2. What is the actual difference between close() and disconnet()? When disconnet() is to be used?

Thanks,
Aviv

### Reply 2 by Coccoliso, 2015-04-01

The disconnection process involves communication with the peer with ACK / FIN exchanges and can be Active or Passive ( depends on connected peer ). In any case, at the end of the disconnection, the status Sn_SR always passes in SOCK_CLOSED and it is quite hard to find SOCK_CLOSING, SOCK_FIN_WAIT or SOCK_LAST_ACK for the speed with which move from one state to another.
I noticed that in LAN is very difficult to read these intermediate states and if you wait a disconnect you get lost forever in an intermediate state while if you connect through internet is quite repeatable.

### Reply 3 by avivf, 2015-04-02

Hello,
I’ve been reading your reply. You mentioned that in a server application it’s better to use close() rather than disconnect().

1. What if my application in a client instead of a server. Should I still use close() rather than disconnet()?

2. What is the actual difference between close() and disconnet()? When disconnet() is to be used?

Thanks,
Aviv

### Reply 4 by Coccoliso, 2015-04-02

In client or server application the problem remains…

- In a communication with an http server where once you’ve sent the request and received the answer instead of making a DISCONNECT for as mentioned above should make a CLOSE to prevent the ACK / FIN that in any case occur even in this case.

- In case of communications with continuous flow at the end does not make DISCONNECT but simply make a CLOSE.

---

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