commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha <aha1...@yahoo.com>
Subject RE: [net]FTPClient.connect() spend long time for "null" host
Date Tue, 15 Jun 2004 06:51:24 GMT
I found that when I use connect(host, port), it will
invoke createSocket() in Class DefaultSocketFactory:

    public Socket createSocket(String host, int port)
    throws UnknownHostException, IOException
    {
        return new Socket(host, port);
    }

But "new Socket(host, port)" function will connect ftp
server with timeout = 0, it will spend long time to
connect a null host.

When I modified the code as following, it looks that
resolved it.

    public Socket createSocket(String host, int port)
    throws UnknownHostException, IOException
    {
        //return new Socket(host, port);
		Socket s = new java.net.Socket();
		java.net.InetSocketAddress addr = new
java.net.InetSocketAddress(host, port);
		s.connect(addr, 5000);
		return s;
    }


To all: Is it correct??? Any comments are welcome!


--- aha <aha1973@yahoo.com> wrote:
> Hi,
> 
> When I use connect("10.0.0.1", 21) to connect "null"
> host, that means no host bind the "10.0.0.1", it
> throws exception after spent long time (about 220s).
> 
> Faint!
> 
> 
> 2001-06-09 19:34:49.117 start
> 
> java.net.ConnectException: Connection timed out
>         at
> java.net.PlainSocketImpl.socketConnect(Native
> Method)
>         at
>
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
>         at
>
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
>         at
>
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
>         at java.net.Socket.connect(Socket.java:434)
>         at java.net.Socket.connect(Socket.java:384)
>         at java.net.Socket.<init>(Socket.java:291)
>         at java.net.Socket.<init>(Socket.java:119)
>         at
>
org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:92)
>         at
>
org.apache.commons.net.SocketClient.connect(SocketClient.java:201)
> ......
> 
> 2001-06-09 19:38:33.792 end
> 
> 
> 
> How can I avoid it ???
> 
> B.R.



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message