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 <[EMAIL PROTECTED]> 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.<init>(Unknown Source)
>> at
>> com.mypackage.TimeoutSettingServerSocketProxy.<init>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: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to