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.

ME


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

// Create runnable for posting
final Runnable mUpdateResults = new Runnable()
{
public void run()
{
updateResultsInUi();
}
};

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
DatagramPacket(buf,buf.length);
for (idx = 0 ; idx < buf.length ; idx++)
buf[idx] = 0;

try
{
rcvd = false;
TheSocket.receive(packet);
response = new String(packet.getData()).trim();
System.out.println("DEBUG:
Listener.doInBackground: Received:
"+packet.getAddress()+" "+packet.getPort()+" "+response);
rcvd = true;
}
catch (Exception e)
{
System.out.println("DEBUG: Rx Timeout");
rcvd = false;
};
mHandler.post(mUpdateResults);
}
};
t.start();
};

private void updateResultsInUi()
{
CompassReceive();

}

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

WifiManager wifi =
(WifiManager)getSystemService(getApplicationContext().WIFI_SERVICE);
MulticastLock lock = wifi.createMulticastLock("mylock");
lock.acquire();



Other Threads

1. How to make this layout in programming?

I have a layout xml . I would like to do that in java programming.
Can anybody help me?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:id="@+id/rl">

  <TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:textColor="#FFFFFF"
    />
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@id/tv1"
    >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv1"
        android:textColor="#FFFFFF"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv2"
        android:textColor="#FFFFFF"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv3"
        android:textColor="#FFFFFF"
        />
  </LinearLayout>
</RelativeLayout>

-- 

2. Sending Email

Hi All,
Anyone tell me...how to send email using current sdk (1.0)??

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

3. Regarding Storing of data in the database in android.

4. Code of Home Screen

5. Android USB adb device not being enumerated.

6. A Question regarding Android system preferences: Settings.Secure

7. Re-using the Android Call Log / Contacts and sms capabilities.