Artog
Artog

Reputation: 1142

Long delay before socket close

Scenario:

I'm building an application that uses Commons Net FTPSClient to connect to a server.

If the connection is broken I want to restart it. I try to accomplish this by using ftp.disconnect();

disconnect() calls socket.close()

Connection break is simulated by simply pulling the cord.

Problem:

socket.close() takes about 9 min (540 sec) to close.

Why is this? and how can i change it?

socket.getSoLinger() returns -1 (disabled) and socket.getSoTimeout() returns 30000 (30 sec)

Upvotes: 1

Views: 852

Answers (2)

jello
jello

Reputation: 151

To help pinpoint the issue you can run netstat to determine what state the client is in (FIN_WAIT, TIME_WAIT, etc) after you have called socket.close(). That should give you some idea on where the delay is at.

Upvotes: 1

Riddhish.Chaudhari
Riddhish.Chaudhari

Reputation: 853

i think it's problem of Control channel keep-alive feature:

During file transfers, the data connection is busy, but the control connection is idle. FTP servers know that the control connection is in use, so won't close it through lack of activity, but it's a lot harder for network routers to know that the control and data connections are associated with each other.

ftpClient.setControlKeepAliveTimeout(300); // set timeout to 5 minutes

and to check it with

    int iReply = ftpClient.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply))
            {
                ftpClient.disconnect();
                System.err.println("FTP server refused connection.");
                System.exit(1);
            }

Upvotes: 1

Related Questions