Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 46076 invoked from network); 3 Sep 2008 01:16:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Sep 2008 01:16:52 -0000 Received: (qmail 39028 invoked by uid 500); 3 Sep 2008 01:16:46 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 38954 invoked by uid 500); 3 Sep 2008 01:16:46 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 38943 invoked by uid 99); 3 Sep 2008 01:16:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Sep 2008 18:16:46 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [72.14.220.152] (HELO fg-out-1718.google.com) (72.14.220.152) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Sep 2008 01:15:45 +0000 Received: by fg-out-1718.google.com with SMTP id d23so1001fga.24 for ; Tue, 02 Sep 2008 18:16:14 -0700 (PDT) Received: by 10.187.195.7 with SMTP id x7mr2156921fap.46.1220404574459; Tue, 02 Sep 2008 18:16:14 -0700 (PDT) Received: by 10.187.221.6 with HTTP; Tue, 2 Sep 2008 18:16:14 -0700 (PDT) Message-ID: Date: Tue, 2 Sep 2008 21:16:14 -0400 From: "James Carman" Sender: jcarman@carmanconsulting.com To: "Commons Users List" Subject: Re: The java.net.SocketException: No buffer space available (maximum connections reached?): listen failed Exception In-Reply-To: <19280979.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <19269806.post@talk.nabble.com> <19280979.post@talk.nabble.com> X-Google-Sender-Auth: 1fd6dab2107a72c0 X-Virus-Checked: Checked by ClamAV on apache.org Does it do the same thing without your custom SocketFactory? On Tue, Sep 2, 2008 at 9:01 PM, chitraa wrote: > > Yup, sure. Here it is: > > public class MySocketFactory implements SocketFactory > { > private int clientTimeout; > private int serverTimeout; > > public MySocketFactory(int clientTimeout, int serverTimeout) > { > this.clientTimeout = clientTimeout; > this.serverTimeout = serverTimeout; > } > > public Socket createSocket(String host, int port) throws > UnknownHostException, IOException > { > return createSocket(host, port, null, 0); > } > > public Socket createSocket(InetAddress address, int port) > throws IOException > { > return createSocket(address.getHostName(), port, null, 0); > } > > public Socket createSocket(InetAddress address, int port, > InetAddress localAddress, int localPort) throws IOException > { > return createSocket(address.getHostName(), port, localAddress, 0); > } > > public Socket createSocket(String host, int port, InetAddress localAddress, > int localPort) throws UnknownHostException, IOException > { > Socket socket = new Socket(); > socket.setSoTimeout(clientTimeout); > SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); > SocketAddress remoteaddr = new InetSocketAddress(host, port); > socket.bind(localaddr); > socket.connect(remoteaddr, clientTimeout); > return socket; > } > > public ServerSocket createServerSocket(int port) throws IOException > { > ServerSocket ss = new ServerSocket (port); > ss.setSoTimeout(serverTimeout); > return ss; > } > > public ServerSocket createServerSocket(int port, int backlog) throws > IOException > { > ServerSocket ss = new ServerSocket (port, backlog); > ss.setSoTimeout(serverTimeout); > return ss; > } > > public ServerSocket createServerSocket(int port, int backlog, InetAddress > bindAddr) throws IOException > { > ServerSocket ss = new ServerSocket (port, backlog, bindAddr); > ss.setSoTimeout(serverTimeout); > return ss; > } > } > > > > jwcarman wrote: >> >> Can we see your implementation of SocketFactory? >> >> On Tue, Sep 2, 2008 at 9:01 AM, chitraa wrote: >>> >>> Hi all, >>> >>> Although the subject of this message indicates that the Exception I am >>> getting is a java thing, I am using the apache.commons.net package and >>> have >>> a suspicion that it could be related to this library. >>> >>> Here's a bit about my program. My program makes a TCPIP connection to >>> other >>> machines and uses the FTP protocol to retrieve files to download on the >>> remote machine. I am using the apache.commons.net.FtpClient java class to >>> provide me with an interface that allows me to connect to the remote >>> machine, log on, list the files that are on the remote computer and >>> download >>> all the files that I need. >>> >>> I have written my own implementation for >>> apache.commons.net.SocketFactory. >>> Also, I have ensured that when I connect to a machine and open a socket, >>> I >>> disconnect when I am done with the connection. >>> >>> After 2 days, I get this exception: >>> >>> java.net.SocketException: No buffer space available (maximum connections >>> reached?): listen failed >>> at java.net.PlainSocketImpl.socketListen(Native Method) >>> at java.net.PlainSocketImpl.listen(Unknown Source) >>> at java.net.ServerSocket.bind(Unknown Source) >>> at java.net.ServerSocket.(Unknown Source) >>> at >>> com.mypackage.TimeoutSettingServerSocketProxy.TimeoutSettingServerSocketProxy.java:28) >>> at >>> com.mypackage.MySocketFactory.createServerSocket(RedflexSocketFactory.java:69) >>> at >>> org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:475) >>> at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1285) >>> >>> After running a few test programs, I realised that this was because the >>> server was having too many open connections. I have checked my program >>> and I >>> have closed all open sockets. So, I was wondering if there is an issue >>> with >>> apache.commons.net? Does FTPClient open up a ServerSocket without closing >>> it? >>> >>> Also, whats interesting is that once this exception has been thrown, I >>> get >>> disconnected from the machine. Reconnecting to it will obviously throw >>> the >>> exception again. However, when I connect to other machines, it throws the >>> same exception: >>> >>> Failed to connect to 192.168.1.2 No buffer space available (maximum >>> connections reached?): connect >>> >>> If the 'no buffer space available' is thrown because of too many open >>> connections on the server, why can't I connect to other servers (which >>> don't >>> have many open connections). Why does the client (my machine) throw that >>> same exception when trying to connect to OTHER machines? >>> >>> Thank you. >>> Kind regards, >>> Chitra >>> -- >>> View this message in context: >>> http://www.nabble.com/The-java.net.SocketException%3A-No-buffer-space-available-%28maximum-connections-reached-%29%3A-listen-failed-Exception-tp19269806p19269806.html >>> Sent from the Commons - User mailing list archive at Nabble.com. >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >> For additional commands, e-mail: user-help@commons.apache.org >> >> >> > > -- > View this message in context: http://www.nabble.com/The-java.net.SocketException%3A-No-buffer-space-available-%28maximum-connections-reached-%29%3A-listen-failed-Exception-tp19269806p19280979.html > Sent from the Commons - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org