You should be using another method to test for port availability. Try 123099's method but include a DatagramSocket to chekc for UDP availability as well.