Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1258778

Can't send datagram packet to the broadcast address.

    XMLWordPrintable

Details

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

    Description

      The included test case is from Eric Petersen of Ascend:

      ###@###.### (Eric Petersen)

      It demonstrates the fact that you can not send a packet to
      the broacast address. 255.255.255.0. I reproduced this on
      Solaris.



      import java.awt.*;
      import java.net.*;
      import java.io.*;

      public class Test implements Runnable
      {
      public static void main(String args[])
      {
      MyFrame win = new MyFrame();
      win.show();
      }

      public void run()
      {
      }
      }

      class MyFrame extends Frame
      {
      TextField dataField=null;
      Button bcastBtn=null;
          public MyFrame()
          {
              super("Type some data to broadcast...");

      setLayout(new FlowLayout(FlowLayout.LEFT,6,6));
      setFont(new Font("Helvetica", Font.PLAIN, 11));
      dataField = new TextField(20);
      add("Data",dataField);
      bcastBtn = new Button("Broadcast");
      add("Broadcast",bcastBtn);
      pack();
          }

          public synchronized void show()
          {
           super.show();
         }

          public boolean handleEvent(Event ev) {

      if(ev.target instanceof Button)
      {
      doBroadcast();
      }

              if(ev.id == Event.WINDOW_DESTROY)
              {
           hide();
      dispose();
      System.exit(0);
           return true;
           }
           return super.handleEvent(ev);
          }

          public boolean doBroadcast()
          {
              try
              {
      // Open a UDP socket for broadcasting
      DatagramSocket socket = new DatagramSocket();
      InetAddress localhost = InetAddress.getLocalHost();
      System.out.println("Local Host "+localhost.toString());

                  int bufLen = dataField.getText().length();
           byte[] buf = new byte[bufLen];

           // Broadcast (address 255.255.255.255, correct?)
      DatagramPacket packet = new DatagramPacket(buf,bufLen,
      // InetAddress.getByName("255.255.255.0"),1000);
      InetAddress.getByName("129.148.27.255" ),1000);


                  socket.send(packet);
          }
      catch( Exception e)
      {
      System.out.println("Exception: "+e.getMessage());
      e.printStackTrace();
      return false;
      }
              return true;
          }
      }

      Attachments

        Activity

          People

            djbrown David Brown (Inactive)
            tkincaidsunw Tom Kincaid (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: