FileDocCategorySizeDatePackage
lookForLocalUDPPorts.javaAPI DocExample539Thu Apr 03 15:25:28 BST 1997None

lookForLocalUDPPorts.java

import java.net.*;

public class lookForLocalUDPPorts {

  public static void main(String[] args) {
    
    DatagramSocket theServer;

    for (int i = 1024; i <= 65535; i++) {
      try {
        // the next line will fail and drop into the catch block if
        // there is already a server running on port i
        theServer = new DatagramSocket(i);
        theServer.close();
      }
      catch (SocketException e) {
        System.out.println("There is a server on port " + i + ".");
      } // end try
    } // end for

  }
  
}