title: UDP port scanning Java finds only 1 open UDP port
body: <p>I have an assigment about port scanning. I am scanning UDP ports of some IP addresses in Java.In my program (assuming everything is OK) I can only find one open UDP port. In the other hands port scanning over "nmap" I get 4 open UDP ports. Can somebody tell me why I can not find more than one ports via Java code?
  By the way I can find the true open port in my code.</p>
  
  <pre><code>int startPortRange=1;
      int stopPortRange=1024;
      InetAddress address = InetAddress.getByName("bigblackbox.cs.binghamton.edu");
      int counter=0;
      for(int i=startPortRange; i &lt;=stopPortRange; i++)
      {
          counter++;      
         try{
  
  
              byte [] bytes = new byte[128];
              DatagramSocket ds = new DatagramSocket();
              DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
              ds.setSoTimeout(100);
              ds.connect(address, i);
              ds.send(dp);
              ds.isConnected();
              dp = new DatagramPacket(bytes, bytes.length);
              ds.receive(dp);
              ds.close();
              System.out.println("open");
              System.out.println(counter);
          }
          catch(InterruptedIOException e){
              //System.out.println("closed");
          }
          catch(IOException e){
              //System.out.println("closed");
          }       
      }
  </code></pre>
  
  <p>Output of above code is
  135 open </p>
  
  <p>When I make same operation in command line using nmap I get more open ports.
  I could not upload an image because I am a new user.
  Thank you
  <img src="https://i.stack.imgur.com/iREBN.png" alt="enter image description here"></p>