title: Sending packets to 255.255.255.255 by Java DatagramSocket fails
body: <p>I'm programming a networking program in java , and I want to send some Packets to 255.255.255.255, but it fails , even when I send them to 192.168.1.255, which according to the output of ifconfig command , is the broadcast address. But when I send them to my mate's IP it works fine. </p>
  
  <p>Here's the code to my program : </p>
  
  <pre><code>public class StackOverFlow {
      public static void main(String[] args) {
          Network net= new Network();
  
          Scanner input= new Scanner(System.in);
          while(input.hasNext())
            net.sendMessage(input.nextLine());
      }
  }
  </code></pre>
  
  <p>I've used DatagarmSocket and DatagramPacket to do so , here's my implementation of the Network :</p>
  
  <pre><code>class Network {
  DatagramSocket socket;
  
  public Network() {
      try {
          socket = new DatagramSocket(8027);
          socket.connect(InetAddress.getByName("255.255.255.255"), 8027);
      } catch (Exception e) {
          System.err.println("Connection failed. " + e.getMessage());
      }
      listen();
  }
  
  public void listen() {
      new Thread() {
          public void run() {
              while (true) {
                  try {
                      byte[] buf = new byte[1000];
                      DatagramPacket packet = new DatagramPacket(buf,
                              buf.length);
                      socket.receive(packet);
                      String message = new String(buf);
                      System.out.println("Recieved: " + message);
                      if (message.equals("end"))
                          return;
                  } catch (Exception e) {
                      System.err.println(e.getMessage());
                  }
              }
          }
      }.start();
  }
  
  public void sendMessage(String message){
      byte[] buf= message.getBytes();
  
      DatagramPacket packet= new DatagramPacket(buf, buf.length);
      try{
          socket.send(packet);
      }catch(Exception e){
          System.err.println("Sending failed. " + e.getMessage());
      }
  }
  </code></pre>
  
  <p>No Exceptions are being thrown.<br>
  I'm in an ad hoc network.<br>
  I'm using MAC OS X 10.6 while my mate is using kubuntu 11.04.
  And here is ifconfig output:</p>
  
  <pre><code>lo0: flags=8049&lt;UP,LOOPBACK,RUNNING,MULTICAST&gt; mtu 16384
  inet6 ::1 prefixlen 128 
  inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
  inet 127.0.0.1 netmask 0xff000000 
  gif0: flags=8010&lt;POINTOPOINT,MULTICAST&gt; mtu 1280
  stf0: flags=0&lt;&gt; mtu 1280
  
  en0: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
  inet6 fe80::21f:f3ff:fed5:4779%en0 prefixlen 64 scopeid 0x4 
  inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
  ether 00:1f:f3:d5:47:79 
  media: autoselect (100baseTX &lt;full-duplex&gt;) status: active
  supported media: autoselect 10baseT/UTP &lt;half-duplex&gt; 10baseT/UTP &lt;full-duplex&gt; 10baseT/UTP     &lt;full-duplex,hw-loopback&gt; 10baseT/UTP &lt;full-duplex,flow-control&gt; 100baseTX &lt;half-    duplex&gt; 100baseTX &lt;full-duplex&gt; 100baseTX &lt;full-duplex,hw-loopback&gt; 100baseTX &lt;full-duplex,flow-control&gt; 1000baseT &lt;full-duplex&gt; 1000baseT &lt;full-duplex,hw-loopback&gt; 1000baseT &lt;full-duplex,flow-control&gt; none
  
  en1: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
  inet6 fe80::21d:4fff:feff:2b4d%en1 prefixlen 64 scopeid 0x5 
  inet 213.233.170.97 netmask 0xfffffc00 broadcast 213.233.171.255
  ether 00:1d:4f:ff:2b:4d 
  media: autoselect status: active
  supported media: autoselect
  
  fw0: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 2030
  lladdr 00:21:e9:ff:fe:bc:79:b2 
  media: autoselect &lt;full-duplex&gt; status: inactive
  supported media: autoselect &lt;full-duplex&gt;
  
  en2: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
  ether 00:1f:f3:b6:2c:be 
  media: autoselect status: inactive
  supported media: none autoselect 10baseT/UTP &lt;half-duplex&gt;
  
  vmnet1: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
  inet 192.168.149.1 netmask 0xffffff00 broadcast 192.168.149.255
  ether 00:50:56:c0:00:01 
  
  vmnet8: flags=8863&lt;UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
  inet 192.168.73.1 netmask 0xffffff00 broadcast 192.168.73.255
  ether 00:50:56:c0:00:08 
  </code></pre>
  
  <p>en0 is the device I'm using to connect to my mate.</p>
  
  <p><strong>Please make it simple, I'm a newbie :)</strong></p>
  
  <p>Thanks in advance.</p>