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("");
                        this.socket = new DatagramSocket(port, this.serverAddr);
                        Log.d(tag, "listening port 5000");
                } catch (Exception e) {
                        Log.d(tag, "Failed accessing server address and 

        public void start() {

        public void run() {
                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, 

                                this.socket.receive(packet);  // Receive the 
                                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 and/or ?


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

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 and see
how the emulator reacts to that.

Any other solutions would be welcomed.

Other Threads

1. Can I play a AAC strem which is in a FLV container?


I'm trying to build a radio player and the client is providing a
stream which is a FLV container with the audio being AAC

When I read the headers it shows up as audio/aacp.

I have tried all possible ways such as using the

1) Streaming through mediaplayer (Does not work)

2) Use the NPR mode of using a proxy stream (I get a broken pipe

3) Play it in chunks ( Plays but I need the SDCard and the playback is
not very great)

4) Use the GPL'd FAAD2 Library but I would have to pay the royalty fee

Can some one help me out on figuring this issue out.

The last option that I have is to have my client change the stream to
mp3 container (which I know that it works)



2. Camera picture taking memory error

In the app I'm working on, I'm using Camera.addCallbackBuffer and
Camera.setPreviewCallbackWithBuffer to control the camera preview.
BTW, this has been one of the best fixes in Froyo yet!  No more GC

I'm trying to take a picture, and sometimes it works, saving the image
to the sd card, and sometimes it doesn't.  When it doesn't work, the
preview is frozen, but the app is still running.  For instance, I can
still call up the menu. So its not locking up the app at all.  I've
tracked it down to a memory allocation issue I believe.  It seems that
the camera is using the buffers from the preview to store the picture
data.  I could be wrong about this.  I've upped the memory buffers
used in the addCallbackBuffer, and it seems it fix the problem, but
shouldn't there be a seperate buffer for the snapped picture data?

Is there a way to allocate a buffer for the Camera.takePictureCallback
routine to store the data into?
Is there a better way to make sure the Camera has enough memory to use
the addCallbackBuffers and take a full size photo?
Is anyone else experiencing this problem using the camera preview
buffers and taking a full size picture?

Any help is greatly appreciated.

Stephen Lebed
Developer of 'On The Level' and 'SL DigiSlate'


3. [Q] Question about Android basic that's a bit more about hardware than software

4. Help me on AsyncTask

5. Solution Found: MyTouch4G ADB

6. isFinishing() & BadTokenException - very weird !!

7. Appeal to Android users with interest in DNA programming