ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: <socket> returns true thought there is no listener
Date Fri, 17 Aug 2007 08:58:34 GMT
Wei Feng Niu wrote:
> Hi,
> 
>          I have a target to detect whether a port is listening, like the
> following:
> 
> ================================================================
> 
> <project name="test" default="test.server">
> 
>     <target name="test.server" description="Test server.">
> 
>         <echo message="trying to test server at localhost:39001..." />
> 
>         <waitfor maxwait="300" maxwaitunit="second" checkevery="5"
> timeoutproperty="server.not.started">
> 
>             <and>
> 
>                 <socket server="localhost" port="39001" />
> 
>             </and>
> 
>         </waitfor>
> 
>         <fail message="server did not start!" if="server.not.started" />
> 
>         <echo message="server has started successfully." />
> 
>     </target>
> 
> </project>
> 
> =================================================================
> 
> Put the codes into a build file and run it, I got the following result:
> 
> ant -f t.xml;netstat -an|grep 39001
> 
> Buildfile: t.xml
> 
>  
> 
> test.server:
> 
>      [echo] trying to test server at localhost:39001...
> 
>      [echo] server has started successfully.
> 
>  
> 
> BUILD SUCCESSFUL
> 
> Total time: 59 seconds
> 
> tcp        0      0 ::ffff:127.0.0.1:39001      ::ffff:127.0.0.1:39001
> TIME_WAIT   
> 
>  
> 
>  
> 
> Thoug there is no any server on 39001 started, after a while the target
> will return with "server has started successfully". It is very strange.
> Seems the <socket> task makes a listener on 39001 and detect it. So far
> I just found the problem on RedHat Linux. And the time that <socket>
> returns are different every time you run the target. Sometimes the
> target works as expected and sometimes works as above.
> 
>  
> 
> Does anybody know what's the cause? Thanks

1. <socket> tries to open a TCP connection; it gets assigned some random 
port..I'd be surprised that it got 39001, though it is a high enough 
value it could happen sometimes. Maybe it depends where the TCP stack 
starts allocating unallocated ports. Try opening a socket to a remote 
site, see what gets opened there.

2. run netstat -p to see the process with the port

3. are you sure the port is closed? Sometimes after a previous run the 
port may still be open.

-steve

2.

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


Mime
View raw message