UDP Connection Not Working on Device

Put your problem here if it does not fit any of the other categories.

UDP Connection Not Working on Device

Postby auser12 » Sun Feb 05, 2012 12:49 am

Hi everyone, I have a slight problem. I am trying to send a string from my Xoom to my laptop via UDP. They are on the same Wi-Fi network. It works fine in the emulator, but when I try it on my device, nothing happens. Here is my code:

Code: Select all
String messageStr="Hello Android!";
         int server_port = 9876;
         DatagramSocket s = new DatagramSocket();
         InetAddress local = InetAddress.getByName("IP Address of Laptop");
         int msg_length=messageStr.length();
         byte[] message = messageStr.getBytes();
         DatagramPacket p = new DatagramPacket(message, msg_length,local,server_port);
         s.send(p);


Thanks for your help.
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Top

Re: UDP Connection Not Working on Device

Postby Phyll » Sun Feb 05, 2012 12:22 pm

Hi auser12,

The most likely reasons would be the internet permission or the wifi is not enabled. Do you have any errors showing up in the logcat that you can share?

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: UDP Connection Not Working on Device

Postby auser12 » Sun Feb 05, 2012 10:30 pm

02-05 15:27:49.629: D/AndroidRuntime(3466): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-05 15:27:49.629: D/AndroidRuntime(3466): CheckJNI is OFF
02-05 15:27:49.820: D/AndroidRuntime(3466): Calling main entry com.android.commands.pm.Pm
02-05 15:27:49.830: W/ActivityManager(162): No content provider found for permission revoke: file:///data/local/tmp/UDPConnection.apk
02-05 15:27:49.830: W/ActivityManager(162): No content provider found for permission revoke: file:///data/local/tmp/UDPConnection.apk
02-05 15:27:49.860: I/PackageManager(162): Removing non-system package:com.neal.udpconnection
02-05 15:27:49.860: I/ActivityManager(162): Force stopping package com.neal.udpconnection uid=10007
02-05 15:27:49.860: I/ActivityManager(162): Killing proc 3204:com.neal.udpconnection/10007: force stop
02-05 15:27:49.860: I/ActivityManager(162): Force finishing activity ActivityRecord{419e4c48 com.neal.udpconnection/.UDPConnectionActivity}
02-05 15:27:49.870: I/WindowManager(162): WIN DEATH: Window{419e2368 com.neal.udpconnection/com.neal.udpconnection.UDPConnectionActivity paused=true}
02-05 15:27:50.650: I/PackageManager(162): Running dexopt on: com.neal.udpconnection
02-05 15:27:50.650: I/PackageManager(162): Package com.neal.udpconnection codePath changed from /data/app/com.neal.udpconnection-1.apk to /data/app/com.neal.udpconnection-2.apk; Retaining data and using new
02-05 15:27:50.710: D/dalvikvm(3478): DexOpt: load 6ms, verify+opt 2ms
02-05 15:27:50.750: I/ActivityManager(162): Force stopping package com.neal.udpconnection uid=10007
02-05 15:27:50.750: W/PackageManager(162): Code path for pkg : com.neal.udpconnection changing from /data/app/com.neal.udpconnection-1.apk to /data/app/com.neal.udpconnection-2.apk
02-05 15:27:50.750: W/PackageManager(162): Resource path for pkg : com.neal.udpconnection changing from /data/app/com.neal.udpconnection-1.apk to /data/app/com.neal.udpconnection-2.apk
02-05 15:27:51.219: D/PackageManager(162): New package installed in /data/app/com.neal.udpconnection-2.apk
02-05 15:27:51.690: I/ActivityManager(162): Force stopping package com.neal.udpconnection uid=10007
02-05 15:27:51.750: D/AmazonAppstore.UpdateService(32666): Received action: com.amazon.mas.client.framework.UpdateService.APP_WAS_UNINSTALLED from intent: Intent { act=com.amazon.mas.client.framework.UpdateService.APP_WAS_UNINSTALLED cmp=com.amazon.venezia/com.amazon.mas.client.framework.UpdateService (has extras) }
02-05 15:27:51.760: D/dalvikvm(2593): GC_EXPLICIT freed 628K, 12% free 6893K/7751K, paused 2ms+7ms
02-05 15:27:51.770: D/dalvikvm(381): GC_EXPLICIT freed 815K, 31% free 15461K/22215K, paused 3ms+24ms
02-05 15:27:51.820: I/ActivityManager(162): Start proc com.android.gallery3d for broadcast com.android.gallery3d/.app.PackagesMonitor: pid=3479 uid=10031 gids={3003, 1015}
02-05 15:27:51.890: D/dalvikvm(162): GC_EXPLICIT freed 1621K, 32% free 17110K/25031K, paused 3ms+10ms
02-05 15:27:51.900: D/PackageManager(162): generateServicesMap(android.accounts.AccountAuthenticator): 5 services unchanged
02-05 15:27:51.930: D/PackageManager(162): generateServicesMap(android.content.SyncAdapter): 16 services unchanged
02-05 15:27:51.930: D/BackupManagerService(162): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.neal.udpconnection flg=0x10000010 (has extras) }
02-05 15:27:51.930: D/PackageManager(162): generateServicesMap(android.accounts.AccountAuthenticator): 5 services unchanged
02-05 15:27:51.950: D/PackageManager(162): generateServicesMap(android.content.SyncAdapter): 16 services unchanged
02-05 15:27:51.960: I/ActivityThread(3479): Pub com.google.android.gallery3d.GooglePhotoProvider: com.google.android.picasasync.PicasaContentProvider
02-05 15:27:51.980: D/BackupManagerService(162): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.neal.udpconnection flg=0x10000010 (has extras) }
02-05 15:27:51.980: V/BackupManagerService(162): updatePackageParticipantsLocked: com.neal.udpconnection
02-05 15:27:52.060: D/dalvikvm(3479): GC_CONCURRENT freed 417K, 7% free 6556K/7047K, paused 2ms+2ms
02-05 15:27:52.090: I/ActivityThread(3479): Pub com.google.android.gallery3d.provider: com.android.gallery3d.provider.GalleryProvider
02-05 15:27:52.120: D/SyncManager(162): setIsSyncable: Account {name=sunil.steelers@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.120: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.120: D/SyncManager(162): setIsSyncable: Account {name=neal.chandnani@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.120: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.190: D/dalvikvm(3479): GC_CONCURRENT freed 467K, 8% free 6629K/7175K, paused 1ms+3ms
02-05 15:27:52.190: D/SyncManager(162): setIsSyncable: Account {name=sunil.steelers@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.190: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.190: D/SyncManager(162): setIsSyncable: Account {name=neal.chandnani@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.190: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.250: I/ActivityManager(162): Start proc com.android.keychain for broadcast com.android.keychain/.KeyChainBroadcastReceiver: pid=3492 uid=1000 gids={1015, 3002, 3001, 3003, 3007}
02-05 15:27:52.330: D/dalvikvm(162): GC_EXPLICIT freed 1282K, 32% free 17043K/25031K, paused 5ms+18ms
02-05 15:27:52.330: D/AndroidRuntime(3466): Shutting down VM
02-05 15:27:52.340: D/dalvikvm(3466): GC_CONCURRENT freed 100K, 83% free 456K/2560K, paused 1ms+0ms
02-05 15:27:52.340: D/jdwp(3466): Got wake-up signal, bailing out of select
02-05 15:27:52.340: D/dalvikvm(3466): Debugger has detached; object registry had 1 entries
02-05 15:27:52.340: I/AndroidRuntime(3466): NOTE: attach of thread 'Binder Thread #3' failed
02-05 15:27:52.450: D/dalvikvm(162): GC_EXPLICIT freed 109K, 33% free 17011K/25031K, paused 3ms+10ms
02-05 15:27:52.510: D/AmazonAppstore.UpdateService(32666): Received action: com.amazon.mas.client.framework.UpdateService.APP_WAS_INSTALLED from intent: Intent { act=com.amazon.mas.client.framework.UpdateService.APP_WAS_INSTALLED cmp=com.amazon.venezia/com.amazon.mas.client.framework.UpdateService (has extras) }
02-05 15:27:52.540: D/BackupManagerService(162): Received broadcast Intent { act=android.intent.action.PACKAGE_REPLACED dat=package:com.neal.udpconnection flg=0x10000010 (has extras) }
02-05 15:27:52.550: V/BackupManagerService(162): updatePackageParticipantsLocked: com.neal.udpconnection
02-05 15:27:52.550: D/SyncManager(162): setIsSyncable: Account {name=sunil.steelers@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.550: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.570: D/SyncManager(162): setIsSyncable: Account {name=neal.chandnani@gmail.com, type=com.google}, provider com.google.android.gallery3d.GooglePhotoProvider -> 0
02-05 15:27:52.570: D/SyncManager(162): setIsSyncable: already set to 0, doing nothing
02-05 15:27:52.650: I/ActivityManager(162): No longer want com.google.android.apps.maps:FriendService (pid 2842): hidden #16
02-05 15:27:52.660: D/AmazonAppstore.UpdateService(32666): Received action: com.amazon.mas.client.framework.UpdateService.APP_WAS_REPLACED from intent: Intent { act=com.amazon.mas.client.framework.UpdateService.APP_WAS_REPLACED cmp=com.amazon.venezia/com.amazon.mas.client.framework.UpdateService (has extras) }
02-05 15:27:52.820: D/AndroidRuntime(3514): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-05 15:27:52.820: D/AndroidRuntime(3514): CheckJNI is OFF
02-05 15:27:52.860: V/MftdService(2860): onHandleIntent checked action=com.ebay.mobile.service.START_MFTD
02-05 15:27:52.860: D/MftdService(2860): Scheduled MftdService to run at 86400000 ms
02-05 15:27:52.860: V/NotificationTrackingService(2860): onHandleIntent, no authenticated user, returning
02-05 15:27:52.880: I/PushService(2860): onHandleIntent: action=1, intent data=Bundle[{push_action=1}]
02-05 15:27:53.050: D/AndroidRuntime(3514): Calling main entry com.android.commands.am.Am
02-05 15:27:53.060: I/ActivityManager(162): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.neal.udpconnection/.UDPConnectionActivity} from pid 3514
02-05 15:27:53.090: D/AndroidRuntime(3514): Shutting down VM
02-05 15:27:53.100: D/dalvikvm(3514): GC_CONCURRENT freed 102K, 81% free 486K/2560K, paused 0ms+1ms
02-05 15:27:53.100: D/jdwp(3514): Got wake-up signal, bailing out of select
02-05 15:27:53.100: D/dalvikvm(3514): Debugger has detached; object registry had 1 entries
02-05 15:27:53.110: I/AndroidRuntime(3514): NOTE: attach of thread 'Binder Thread #3' failed
02-05 15:27:53.220: D/dalvikvm(3528): Late-enabling CheckJNI
02-05 15:27:53.220: I/ActivityManager(162): Start proc com.neal.udpconnection for activity com.neal.udpconnection/.UDPConnectionActivity: pid=3528 uid=10007 gids={3003}
02-05 15:27:53.280: D/dalvikvm(3528): Debugger has detached; object registry had 1 entries
02-05 15:27:53.350: D/OpenGLRenderer(381): Flushing caches (mode 1)
02-05 15:27:53.350: D/dalvikvm(381): GC_CONCURRENT freed 1436K, 29% free 15984K/22215K, paused 3ms+51ms
02-05 15:27:53.370: D/OpenGLRenderer(381): Flushing caches (mode 0)
02-05 15:27:53.420: D/dalvikvm(2593): GC_CONCURRENT freed 109K, 8% free 7204K/7751K, paused 3ms+4ms
02-05 15:27:53.710: D/dalvikvm(2593): GC_CONCURRENT freed 387K, 7% free 7255K/7751K, paused 4ms+4ms
02-05 15:27:53.910: D/libEGL(3528): loaded /system/lib/egl/libGLES_android.so
02-05 15:27:53.920: D/libEGL(3528): loaded /system/lib/egl/libEGL_tegra.so
02-05 15:27:53.940: D/libEGL(3528): loaded /system/lib/egl/libGLESv1_CM_tegra.so
02-05 15:27:53.940: D/libEGL(3528): loaded /system/lib/egl/libGLESv2_tegra.so
02-05 15:27:53.960: D/OpenGLRenderer(3528): Enabling debug mode 0
02-05 15:27:54.010: I/ActivityManager(162): Displayed com.neal.udpconnection/.UDPConnectionActivity: +814ms
02-05 15:27:59.880: I/ActivityManager(162): No longer want com.google.android.apps.maps:LocationFriendService (pid 2905): hidden #16


This is all that appears in the LogCat when run the application.

As for the internet permission I have this line in my AndroidManifest:

Code: Select all
<uses-permission android:name="android.permission.INTERNET"/>
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Re: UDP Connection Not Working on Device

Postby Phyll » Mon Feb 06, 2012 12:27 am

Hi auser12,

How about the WIFI permissions? It looks like that pile of stuff was out cruzing around on the internet. Is the WIFI on and connected? The emulator is kind of a special case. Some routers are going to be troublesome. Anything else you can add? I didn't see any error that cause the VM to shut down. That usually is something like a permission.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: UDP Connection Not Working on Device

Postby auser12 » Mon Feb 06, 2012 4:39 am

OK, at first I was trying to connect my Xoom to a Windows 7 Virtual Machine on my Mac. But I just tried to connect my Xoom to my Mac (not on a Windows 7 virtual Machine) and it worked fine. So I'm assuming that both devices have to be on the same Wi-Fi network. Is there any way that I can connect both devices via Wi-Fi without them being on the same Wi-Fi network.
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Re: UDP Connection Not Working on Device

Postby Phyll » Mon Feb 06, 2012 12:06 pm

Hi auser12,

I'm afraid I'm just not understanding. If it works from your Android device to your Mac then the trouble probably isn't in your Android device but the PC. I don't know what you are using for a server, but whatever it is in the virtual machinge must not be doing the same thing as the native app. And yes, I think they would have to be on the same network or they would be after they were connected together anyway.

I'm afraid I'm just not being much help.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Re: UDP Connection Not Working on Device

Postby auser12 » Tue Feb 07, 2012 6:05 am

I believe that on the virtual machine, the Wi-Fi is dependent on the Mac's Wi-Fi, so that may be why it was not working. Thanks for all your help.
auser12
Freshman
Freshman
 
Posts: 8
Joined: Sun Feb 05, 2012 12:38 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 12 guests