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. V4l2 USB Camera Integration with Android (Froyo & Eclair)

Hi,

We have ported V4L2 support for USB camera to Android (Froyo & Eclair) on
BeagleBoard.
Also, implemented HAL layer which acts as interface between V4L2 based
camera driver in kernel and the Android framework.

Source code can be found from following locations :

http://gitorious.org/android-enablement/framework-base/commits/beagle-froyo-cam-dev

http://gitorious.org/android-enablement/system-core/commits/beagle-froyo-cam-dev

http://gitorious.org/android-enablement/omap-3530-beagleboard/commits/beagle-froyo-cam-dev

http://gitorious.org/android-enablement/omap-3530-manifest/commits/master


We appreciate your joining our open source initiative, reviewing our work
and sharing your knowledge & experiences with us.
Google groups : coredru...@googlegroups.com
Source code repositories :
http://gitorious.org/~coredruids<http://www.google.com/url?sa=D&q=http://gitorious.org/%7Ecoredruids&usg=AFQjCNE_FlSr-EdGHsLMjLU3evOfyqhDgQ>(Android
Enablement)
Follow us on twitter :
http://twitter.com/coredruids<http://www.google.com/url?sa=D&q=http://twitter.com/coredruids&usg=AFQjCNHQDDnWtIEkGaMXZErmTHJHXzlsFA>

Thanks,
CoreDruids Team

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. App Widget with AlarmManager... full example source?

Hi all,

    I've created a simple app widget for personal use that queries a
site from the internet, parses the XML received and displays some info
from it.  I'm using a Droid X, if that makes a difference; both in the
emulator and as physical hardware, developing in the Android version
of the MotoDev IDE.

    No matter what I put in updatePeriodMillis, the shortest refresh
time I can get is 30 minutes (I thought this was a 1.6 only bug but
apparently not since I'm running 2.1) and I want it to refresh every 5
minutes, with some caveats.  I don't want the widget to refresh when
the screen is off and I want it to refresh immediately upon waking up
the screen.  My search for information says to set updatePeriodMillis
to 0 and use the AlarmManager instead, but I can't find any complete
code examples on just how to do this.

    Obviously, I'm new to Android development, and Java in general
actually, but I've been a developer for a very long time with
experience in just about every other language.  Currently working in
C#, so I thought I'd be able to jump in fairly easily.  Can anyone
point me to sample code or an open source project that does what I'm
looking for?  I have other questions, but until I get this piece
working they don't really matter.  :)

Ricoware

-- 

3. Fetch recurrent events

4. (WTA & WTS) root LG Optimus GT 540

5. How can I delete the black shadow above framelayout in the tabwidget

6. Exchange 2010

7. How to send email with pictures attachment