title: Send data through UDP from android to external sensor
body: <p>I'm trying to send some data from my android to an external sensor through wifi connection. While I am able to send data from the sensor to the android with a UDP connection with success, I'm unable to do the opposite. The code where the data are send is the one below:</p>
  
  <pre><code>public void onClick(View v) {
              Thread t = new Thread(){
                  @Override
                  public void run(){
                      while(true){
                          int server_port = 12345;
                          byte[] message = "1".getBytes();
                          System.out.println(message.toString());
                          try {
                              InetAddress local = InetAddress.getByName("255.255.255.255");
                              DatagramPacket p = new DatagramPacket(message,message.length,local,server_port);
                              DatagramSocket s = new DatagramSocket();
  
                              s.send(p);
                              s.close();
                          } catch (IOException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                      }
                  }
              };
              t.start();
          }
  </code></pre>
  
  <p>As you can see above, OnClick of a button, I want the app to send the data through UDP. The problem is that when i try to do so, this error occurs:</p>
  
  <pre><code>11-24 16:10:13.335: W/System.err(8077): java.net.SocketException: sendto failed: ENETUNREACH    (Network is unreachable)
  11-24 16:10:13.335: W/System.err(8077): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
  11-24 16:10:13.335: W/System.err(8077):at libcore.io.IoBridge.sendto(IoBridge.java:475)
  11-24 16:10:13.335: W/System.err(8077):at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182)
  11-24 16:10:13.335: W/System.err(8077):     at java.net.DatagramSocket.send(DatagramSocket.java:284)
  11-24 16:10:13.343: W/System.err(8077):     at com.example.waspmoteagriculture.MainActivity$3$1.run(MainActivity.java:97)
  11-24 16:10:13.343: W/System.err(8077): Caused by: libcore.io.ErrnoException: sendto failed: ENETUNREACH (Network is unreachable)
  11-24 16:10:13.343: W/System.err(8077):     at libcore.io.Posix.sendtoBytes(Native Method)
  11-24 16:10:13.343: W/System.err(8077):     at libcore.io.Posix.sendto(Posix.java:151)
  11-24 16:10:13.343: W/System.err(8077):     at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
  11-24 16:10:13.343: W/System.err(8077):     at libcore.io.IoBridge.sendto(IoBridge.java:473)
  11-24 16:10:13.343: W/System.err(8077):     ... 3 more
  </code></pre>
  
  <p>I have already included the network permission. Also I should mention that the sensor is connected to android's wifi hotspot in order to send information to the mobile. I don't know if there is a problem in receiving data that way.</p>
  
  <p>Is there any problem with the code or is this error related to something different? Thank you in advance.</p>