2

Imagine that you have three Android phones (A, B and C) connected to the same access point. So each phone has a different IP address. For example:

  • A is at 192.168.1.50
  • B is at 192.168.1.60
  • C is at 192.168.1.70

In each one I've the same app installed. In this app there are two UDP sockets:

DatagramSocket sendSocket = new DatagramSocket();
DatagramSocket receiveSocket = new DatagramSocket(55000);

Since each phone is at a different IP address every phone can send packets to every other phone. For example, to send a packet to A from B:

InetAddress address = InetAddress.getByName("192.168.1.50");
byte[] data = "Hello".getBytes();
DatagramPacket sendPacket = new DatagramPacket(data, data.length, address, 55000);
sendSocket.send(sendPacket);

Now the question is: what is the best approach to develop and debug this application using three emulators on the same machine, such that the code to run it in the emulator is almost the same code to run it on a real setup?

Attempts I've made:

  • Using the code provided here I've launched two emulators on the same machine and printed their IP addresses, obtaining the same IP address for both emulators: fe80::5054:ff:fe12:3456%eth0. So a dead end.
  • Launched only two emulators, each one on specific and different ports for the receive and send sockets. This approach works fine, but it isn't usable with more machines as the redirects and deploys start to become rather bothersome and complicated. Not to mention the fact that I've to play with the 10.0.2.15 and 10.0.2.2 IP addresses to get it working.
Community
  • 1
  • 1
Simão Martins
  • 1,210
  • 11
  • 22
  • For that `%eth0`, is that the _same_ `eth0` mac address on both emulators? (Perhaps the host?) Or is that `eth0` address _different_ for each of the emulators? (Perhaps randomly generated?) – sarnold Apr 24 '12 at 23:55

1 Answers1

0

I don't have a good idea, and it is kind of a workaround, but you could create two VMs (I use VirtualBox for VMs, and it is free), put Linux (maybe Ubuntu) on them, install the SDK and put your code on them to test it there.

Better idea: Create multiple AVDs. Debug your app on each one. Just (in Eclipse) F11, quit. Close AVD. Launch other AVD. Repeat for each AVD. When you're ready, start them all and launch the app from the app menu on the emulators.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
glen3b
  • 693
  • 1
  • 8
  • 22