Not able to receive UDP Data

by Scott » Fri, 18 Mar 2011 00:20:03 GMT


Sponsored Links
 Hi

I am trying to receive UDP data sent from server to my android
emulator client. But i am not able to receive the UDP data in my
android client application which is running on emulator.
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);

1) Can you please let me know how to fix it and receive UDP data on
emulator from server application running on some other system.

2) Will i face same problem in receving UDP data if i run my client on
the Android hardware/Android based mobile.

3) Will i face similar problem in receving the TCP based data when
running the application on the Android Emulator.

Kindly pleas guide/help me to get the answers to the above queries.

-- 



Re: Not able to receive UDP Data

by Indicator Veritatis » Fri, 18 Mar 2011 08:09:18 GMT


 Step 1: make sure you can receive TCP. Step 2: open the right UDP
ports on your firewall and run Wireshark if you are still not
receiving anything. Debug based on what you see.Step 3: get it working
on a real phone using WiFi on the same local network as your emulator.

If it then fails when you use your phone carrier's data service, the
problem is almost certainly their firewall.




-- 


Sponsored Links


Re: Re: Not able to receive UDP Data

by Miguel Morales » Fri, 18 Mar 2011 08:20:45 GMT


 I've read people on the internet recommending to use UDP for game networking
on Android.  However, when I was attempting to implement it using my real G1
device on Tmobile.  However, I didn't have any success.  I don't really
recall having tried it on the emulator, but I probably did.
If anyone had any luck implementing a udp server on an Android device, I'd
be interesting to hear how.








-- 
~ Jeremiah:9:23-24
Android 2D MMORPG:  http://solrpg.com/ http ://www.youtube.com/user/revoltingx

-- 



Re: Not able to receive UDP Data

by emymrin » Fri, 18 Mar 2011 16:34:43 GMT


 UDP works well on emulators and devices.

DatagramSocket socket = new DatagramSocket(port);
byte[] data = new byte[1000];
DatagramPacket datagram = new DatagramPacket(data, 0, data.length,
null, 0);
socket.receive(datagram);







-- 



Re: Re: Not able to receive UDP Data

by Miguel Morales » Fri, 18 Mar 2011 17:01:39 GMT


 Can you verify this works on a device through a regular carrier signal and
not through wifi?










-- 
~ Jeremiah:9:23-24
Android 2D MMORPG:  http://solrpg.com/ http ://www.youtube.com/user/revoltingx

-- 



Re: Not able to receive UDP Data

by Indicator Veritatis » Sat, 19 Mar 2011 09:40:49 GMT


 t worked when I did it with my G2 on T-Mobile. It worked with either
one of WiFi or 4G (the carrier's data).

But I said to debug on WiFi first, since there you have greater
control and transparency: you can run Wireshark and see configuration
on more points in the network. If you root your phone, you can even
run tcpdump on the phone.

On Mar 18, 2:01am, Miguel Morales <therevolti...@gmail.com> wrote:

--



Re: Re: Not able to receive UDP Data

by Miguel Morales » Sat, 19 Mar 2011 10:19:04 GMT


 reat, it's been a while since I played with it because I implemented a
reliable and good enough tcp solution. I'll revisit this if necessary to
improve performance, hopefully this helps the OP resolve his problem.
I was worried that some carriers would not allow UDP to phones, I'll still
have to think of the balance between reliability and performance.

Thanks.

On Fri, Mar 18, 2011 at 6:40 PM, Indicator Veritatis <mej1...@yahoo.com>wrote:




--
~ Jeremiah:9:23-24
Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx

--



Other Threads

1. Playing video in android

Play video on android
-------------------------------------

I'm trying to play video files on android...can anyone please help
me...
I'm not able to see the video but audio works fine... here is the code

PLEASE HELP ME... BY GUIDING ME.. BY CORRECTING THE CODE
OR WITH ANY NEW CODE

package com.vi3;

import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Surface;
import android.view.Window;
//import android.view.Menu.Item;



public class vi3 extends Activity
{
   private static final String LOG_TAG = "|||||||||||||||||";
   private MediaPlayer mp;


   private Preview mPreview;
   //private myAcListener myListener = new myAcListener()this;
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle icicle)
   {
      super.onCreate(icicle);
      Log.i(LOG_TAG, "CameraApp.onCreate");
      mPreview = new Preview(this);
      //requestWindowFeature(W);


    //  stopMedia();
       //     releaseMedia();
      setContentView(R.layout.main);


      //setContentView(mPreview);
      playMedia("");


   }


   private void playMedia(String s_filePath)
   {
      setContentView(mPreview);
      //s_filePath = "/tmp/mp4.mp4";
      s_filePath =  "/data/local/video/test_qcif_200_aac_64.mp4";
      //s_filePath = "/tmp/test.mpg";
      //s_filePath = "/tmp/3.3gp";
      Log.i(LOG_TAG, "CameraApp.playMedia");
      mp = new MediaPlayer();
      try
      {
         mp.setDataSource(s_filePath);
      }
      catch (IllegalArgumentException e)
      {
         // TODO Auto-generated catch block
         Log.v(LOG_TAG,
"CameraApp.playMedia:IllegalArgumentException");
         e.printStackTrace();
      }
      catch (IOException e)
      {
         Log.v(LOG_TAG, "CameraApp.playMedia:IOException");
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      try
      {


         //mp.setDisplay(mPreview.getHolder().getSurface());
         mp.prepare();
         int i = mp.getDuration();
         Log.i(LOG_TAG, "Duration:" + String.valueOf(i));
         mp.start();
      }
      catch (Exception e)
      {
         Log.v(LOG_TAG, e.toString());
         mp.stop();
         mp.release();
      }
      //setContentView(mPreview);
   }


   private void pauseMedia()
   {
      Log.i(LOG_TAG, "CameraApp.pauseMedia");
      if (null != mp)
      {
         mp.pause();
      }
   }


   private void stopMedia()
   {
      Log.i(LOG_TAG, "CameraApp.stopMedia");
      if (null != mp)
      {
         mp.stop();
      }
   }
   private void releaseMedia()
   {
      Log.i(LOG_TAG, "CameraApp.releaseMedia");
      if (null != mp)
      {
         mp.release();
      }
   }
   class Preview extends SurfaceView implements
SurfaceHolder.Callback
   {
       SurfaceHolder   mHolder;
       private boolean         mHasSurface;
       Preview(Context context) {
           super(context);


           mHolder = getHolder();
           mHolder.addCallback(this);
           mHasSurface = false;


           //mHolder.setFixedSize(320, 240);
           mHolder.setFixedSize(176, 144);
           //mHolder.setFixedSize(192, 242);
       }


       public void surfaceCreated(SurfaceHolder holder) {
           // The Surface has been created, start our main acquisition
thread.
           mHasSurface = true;
       }


       public void surfaceDestroyed(SurfaceHolder holder) {
           // Surface will be destroyed when we return. Stop the
preview.
           mHasSurface = false;
       }


       public void surfaceChanged(SurfaceHolder holder, int format,int
w, int h) {
           // Surface size or format has changed. This should not
happen   in this
           // example.
       }
   }


}

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

2. How to make the sound heard over the phone.

If I am on a line with another person and I switch to another app and
play a sound using the code below:

MediaPlayer mMediaPlayer = MediaPlayer.create(this, R.raw.mysound);
mMediaPlayer.start();

is there a way to make the sound be heard by the other person on the
call?
Is there a separate API?

Thanks.
--~--~---------~--~----~------------~-------~--~----~

3. transparent textures...

4. Please help me in defining the style of my widget in my theme.

5. How to use android:pathPattern attribute in intent filters?

6. Need some help at testing an Android game

7. seek operation during multimedia playback - opencore