Friday, April 20, 2012

ANT: simple way how to check any port availability

When you test some distributed applications you sometimes experience connection problems and the first step to troubleshoot is to check is the TCP port is available. Here is the simple ANT script to do that:

<target name="checkPortAvailablility">
 <condition property="portAvailable">
  <socket server="localhost" port="1433"/>
 <fail unless="portAvailable" message="Port is unavailable."/>