1

All I want is my UDP broadcast to work:

    @Override
    protected String doInBackground(String[] params) {
        try {
            DatagramSocket datagramSocket = new DatagramSocket();
            datagramSocket.setBroadcast(true);
            byte[] buffer = "test".getBytes();
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("192.168.0.255"), 8899);
            datagramSocket.send(packet);
            System.out.println("Package sent.");
            System.out.println("Data: " + buffer);
            System.out.println("Broadcast address: " + this.broadcastAddress);
            System.out.println("--------------------------");
        } catch (Exception e) {
            System.out.println("Package not sent: " + e.getMessage());
            e.printStackTrace();
        }
        return "complete";
    }

This code gets executed on an onClick event by a button and is inside an AsyncTask.

The log for 2 clicks is:

System.out﹕ Package sent.
System.out﹕ Data: [B@3b9b0914
System.out﹕ Broadcast address: /192.168.0.255
System.out﹕ --------------------------
System.out﹕ Package sent.
System.out﹕ Data: [B@3090d7b2
System.out﹕ Broadcast address: /192.168.0.255
System.out﹕ --------------------------

So it looks like it's working. But it's not since I can't catch it with Wireshark.

What I've tried is using an UDP package sender on my phone, and that works.

Maybe it's because I can't send UDP packages like this on my watch? Does anyone have an idea on what to search for?

Sem
  • 4,477
  • 4
  • 33
  • 52

1 Answers1

2

You are correct: Android Wear devices do not have access to the internet themselves: your phone app needs to handle all internet connections and forward the results to your Wearable app via the Wear Data Layer

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Heh, guess I was being to optimistic to be synced automatically. Guess I'll have to find a way on how to execute code on the phone then. – Sem Jan 13 '15 at 18:58
  • If this helped answer your question, please accept the answer. – ianhanniballake Jan 13 '15 at 19:07
  • It helped in a way that everything I wrote is rubbish. Not on how I need to do a simple broadcast on my Android Wear device. – Sem Jan 14 '15 at 09:41