Routing UDP data to the emulator

by Tim » Fri, 27 Mar 2009 01:11:59 GMT


Sponsored Links
 I've been scouring the forums and found similar issues like this, but
the solutions seems not to be working.

What we're doing is trying to receive data from an external server via
UDP. At the moment, doing a tcpdump on linux provides information that
yes, there is data coming into my computer. From here, however, things
become murky.

I have tried the following two tactics:

telnet localhost 5554

where 5000 is the port on my computer that is receiving data and 5000
is the port where Android is listening to. This achieves nothing.

The other tactic is the adb forward, which has the same results.

The UDP Server code is as follows:

public class Server extends Thread {
        private InetAddress serverAddr;
        private DatagramSocket socket;

        private static int port = 5000;
        private static final String tag = "UDP Server";

        public Server() {
                try {
                        this.serverAddr = InetAddress.getByName("10.0.2.15");
                        this.socket = new DatagramSocket(port, this.serverAddr);
                        Log.d(tag, "listening port 5000");
                } catch (Exception e) {
                        Log.d(tag, "Failed accessing server address and 
socket");
                }
        }

        public void start() {
                super.start();
        }

        public void run() {
                Looper.prepare();
                while(true) {
                        try {
                                byte[] buf = new byte[43];
                                /* Prepare a UDP-Packet that can
                                 * contain the data we want to receive */
                                DatagramPacket packet = new DatagramPacket(buf, 
buf.length);

                                this.socket.receive(packet);  // Receive the 
UDP-Packet
                                Log.d(tag, "Received: '" + new 
String(packet.getData()) + "'");
                        } catch (IOException e) {
                                Log.e(tag, "Error", e);
                        }
                }
        }
}

What this should do is listen to Android's network/ethernet interface
and output the recieved data (if there is any). What I get is nothing.
Android does not say that there is an error in Logcat or that anything
is received. This seems to tell me that the information is not being
redirected properly to the emulator.

Any thoughts on getting this redirection business settled?

--~--~---------~--~----~------------~-------~--~----~



Routing UDP data to the emulator

by David Turner » Fri, 27 Mar 2009 03:24:26 GMT


 Did you try listening to 0.0.0.0 and/or 10.0.2.2 ?





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Routing UDP data to the emulator

by Tim » Sat, 28 Mar 2009 23:33:16 GMT


 I did a check using netstat and found that when I routed the udp
packet using
telnet localhost 5554

that the port that is listening to is
0.0.0.0:5000

which does make things a bit better in terms of where its going to,
but the emulator
can't seem to make that last connection to it.

I'm going to try writing some code that will forward that data to
0.0.0.0:5000 and see
how the emulator reacts to that.

Any other solutions would be welcomed.
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Google Maps Sights Overlay

Hi,

when using the stock Google Maps application on an Android phone,
there are quite some sights (like churches, museums, ...) displayed in
the MapView. Those are also clickable and one can access further
information about them. Is it somehow possible to get access to this
"sight overlay" in an own application that uses a MapView? If yes, how
could I do this?

Thank you in advance,
Hendrik

-- 

2. bluetooth apps for android

Is there anyway of testing bluetooth applications for android phone
without actually having a real android device. I am asking this
because the emulaator does not support bluetooth.

-- 

3. Weird behavior of MapView

4. how to implement getitem(position) in image adapter of hello-gridview to return customized imageview

5. Using SQLite to get information

6. unable to update the app

7. Importing existing projects to Android