Thanks all,
I did stumble accross a nifty function that checks whether a port is available or not:
public static boolean port_available(int port)
{
ServerSocket ss = null;
DatagramSocket ds = null;
try
{
ss = new ServerSocket(port);
ss.setReuseAddress(true);
ds = new DatagramSocket(port);
ds.setReuseAddress(true);
return true;
}
catch (IOException e)
{ }
finally
{
if (ds != null)
{
ds.close();
}
if (ss != null)
{
try
{
ss.close();
}
catch (IOException e)
{
}
}
}
return false;
}