MultiCast RX Problem

by slasher » Thu, 14 Oct 2010 02:08:38 GMT

Sponsored Links
 ood afternoon,

Platform is DROID X running V2.2OS. Have successfully connected to
Multicast server and am receiving broadcasts for a period of a period
of time (15-30 seconds) after which the receive function times out and
no other data is received. I can confirm the Multicast broadcast
remains active. Additionally, a restart of the application permits
reception of broadcast again (once again for about 15-30 seconds).
Broadcast is a simple text string approximately 30 ASCII characters
about 20 times a second.

Receive function is implemented in a separate thread as the Multicast
receive function is a blocking function.

If receive function is placed in main thread, this behavior does not
occur (i.e., I receive broadcasts indefinitely). However, I cannot
keep it in the main thread as there are a series of Multicast
receivers required for the application.

Have also tried numerous threading implementations (runnable, callable
as defined below) as well as extremely large buffers. It appears (and
this is purely an observation of the behavior, not a diagnosis) that
the network stack somehow fails to de-allocate memory on each receive
and that eventually is corrupted.

Code Follows...

Any thoughts or help is greatly appreciated. Thanks in advance.


public class Video1 extends Activity
MulticastSocket TheSocket;
final Handler mHandler = new Handler();

// Create runnable for posting
final Runnable mUpdateResults = new Runnable()
public void run()

protected void CompassReceive()
// final Runnable CompassReceive = new Runnable()
Thread t = new Thread()
public void run()
int idx;
byte[] buf = new byte[256];
boolean rcvd = false;

String response = "";
DatagramPacket packet = new
for (idx = 0 ; idx < buf.length ; idx++)
buf[idx] = 0;

rcvd = false;
response = new String(packet.getData()).trim();
Listener.doInBackground: Received:
"+packet.getAddress()+" "+packet.getPort()+" "+response);
rcvd = true;
catch (Exception e)
System.out.println("DEBUG: Rx Timeout");
rcvd = false;

private void updateResultsInUi()


public void onCreate(Bundle savedInstanceState)

WifiManager wifi =
MulticastLock lock = wifi.createMulticastLock("mylock");

Other Threads

1. Suggestions on sharing code between standard Java & Android

We have a large, complex, Java client/server application that is
deployed in Java Swing.  We hope to leverage this codebase and reuse a
lot of the client-side model, controller, and communication code in a
new Android port of this application.  Does anyone have thoughts on
how best to do this (FYI, I use Jetbrains IDEA as my IDE, not

For example, several questions come to mind:

- is it better to create a new IDE project for the Android project, or
just add an Android module to the existing IDE project (I prefer the
latter to take advantage of global refactorings).

- if adding an Android module to the current IDE project, how does one
best share lower-level Modules across Java Swing and Android?  Things
become very problematic because Android does not ship with the full
standard JDK, and therefore code must be moved, refactored, or even
deleted if it depends on JDK packages that are not available on
Android.  This means that for a pre-existing Util module to be shared
across the platforms, we may have to create a new lower-level version
of that Module that only depends on the packages that Android has
available to it.

- I've also found through experimentation that when I try to depend on
a pre-existing module that has Jar dependencies of it's own, the
Dalvik conversion process doesn't always successfully convert that Jar
into Android format (possibly because it contains unsupported code).
What's confusing is that the Dalvik conversion works on certain jars
that contain unsupported code, but not on others.  So the conversion
process must be ignoring code that isn't referenced somehow.  In
summary, I've encountered a lot of problems trying to depend on third-
party jars on Android, and I'm wondering if anyone else has the same
problems, or suggestions?

- another way to approach this is to copy the shared code into the
Android project and give up the ideal of trying to share the code, and
just maintain two distinct code bases (this is not at all ideal, but
it may be the most painless route).

- I have another specific question about the Dalvik VM conversion
process.  Exactly how does that process work?  Does it strip out code
that is unsupported on Android?  For example, I had a JAXB generated
file which referenced the import javax.xml.bind.annotation.* classes
that are not available on Android.  With my Android module SDK set to
the main JDK, that code DID compile and DID get converted to Dalvik,
despite the fact it references classes that are not available on
Android.  I did this by adding a dependency to another pure-java
module that has the jaxb.jar as its dependency.  Did the Dalvik
converter actually convert the entire JAXB jar and put it onto
Android, or did it just strip out the JAXB classes and references from
the bytecode that are not available on Android?

I'm very curious about how this all works, because the answer will
have a significant impact on how we move forward on our project.  We
have a lot of code that is written to the standard JDK that we'd like
to reuse on Android.  The code certainly does references packages that
are not available on Android, but we may not necessarily hit those
code paths from inside Android.  But if the system will automatically
strip out the unavailable code paths for us, to allow us to reuse the
same source code, that would be very beneficial.  Just wondering if
anyone has insights on this.


2. How to detect click on complex images/polygons

I am trying to have a complex image like this[http://] in my
application. I want to let users click on the complex polygons
(countries with borders in this case) and highlight the polygon they
clicked on. I have the images that I need to use for that state.

How can I achieve this in android. [Preferably from Java but please
let me know any other options that are feasible].

Thank you


3. Beginner type question on scope

4. Intent filter question

5. loading xml items to an array not working... what is wrong with my code?

6. Recycling MotionEvents

7. Split screen om android