Send a data packet from host PC application to Emulator

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Send a data packet from host PC application to Emulator

Postby ravinsp » Fri Feb 20, 2009 3:56 pm

Hi, I'm new to Android programming and does not like Android Emulator networking very much!

I have read SDK documentation regarding emulator networking and some worthy tutorials on this site. But I have yet to find a way to send a message (UDP packet) from a host PC application to an android applciation. Is this not possible?

In the documentation it says, emulator is hidden behind a router. Is there anyway I can view activities of these virtual routers. So I can verify whether the virtual router actually received a data packet sent by an application in host PC.

Isn't there anyway I can give the emulator a regular IP address and use it just like a virtual machine connected to my network?

(I need to do this on the official SDK without tampering with emulator images)

My OS is Windows (vista64). Using Android 1.0 r2.

Any help is appreciated and I found this site very helpful for me.
-RavinSP-
ravinsp
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 20, 2009 3:35 pm
Location: Sri Lanka

Top

Postby MrSnowflake » Sat Feb 21, 2009 10:54 am

It is possible to setup a tcp/ip connection between pc and the device (when connected through usb). You need a server app and a client, and forward some port of the emulator to some port of the developer machine:
adb forward tcp:<port> tcp:<port>
The bad thing is, you probably have to forward this port after every device shutdown. Though, this can be set using ddms (I guess).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby ravinsp » Sat Feb 21, 2009 7:05 pm

Thanks for the reply.

This is the exact problem I worry about. In real world I would not have to set these port redirection or anything right? I would simply send my data (UDP or TCP) from source IP to destination IP. The fact that the emulator is hidden behind virtual routers limits the flexibility of networking.

If I set a port redirection for emulator, then it starts listening on that port on my PC. So I can't make any other program listen on that port because that is already in use by the emulator. In my case programs on both locations are required to listen on the same port number.

I wouldn't have this problem when using VMWare virtual machines. I would simply communicate directly with the virtual machine's IP. I cannot understand why google have designed android emulator networking the way it is now.

In this way, the emulator does not truly emulate real world Wi-Fi networking. I guess I'll have to buy a real device for my purpose.

Don't you agree?
-RavinSP-
ravinsp
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 20, 2009 3:35 pm
Location: Sri Lanka

Postby MrSnowflake » Sun Feb 22, 2009 1:20 pm

I think this way of working is the same with a device. Because debugging works the same for emulator or device. I don't think the driver gives the device a different ip address, so you still have to connect to localhost:<port>.

If you want multiple programs to be communicating with a device at the same time you should adb forward multiple ports.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby ravinsp » Sun Feb 22, 2009 1:44 pm

Thanks MrSnowflake for the information.

As I get it, this behavior is exhibited in debugging only.

If I get a real device I'd have to use the USB cable to upload my program. Then without relying on the cable, if I directly use my wi-fi network to communicate between my PC and the device, things would be normal. The PC application will be able to directly connect with the Android device IP (assigned by Wi-Fi network).

If I rely on debugging mechanisms (emulator or USB cable), I wouldn't be able to truly get the feeling of Wi-Fi networking. Isn't it? Please correct me if I'm wrong since I have to truly make sure of this before buying one in vain.

Thanks for the help.
-RavinSP-
ravinsp
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 20, 2009 3:35 pm
Location: Sri Lanka

Postby MrSnowflake » Sun Feb 22, 2009 2:10 pm

You are correct. When connected with usb, the ip of the device is not a network ip, but just 127.0.0.1 from the pc.

I think Google did it this way, bacause they wanted to deliver a real thread free mobile device. Just like they did the updates ota.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby ravinsp » Sun Feb 22, 2009 4:06 pm

Thanks for your help. but disappointed though :-(
-RavinSP-
ravinsp
Freshman
Freshman
 
Posts: 6
Joined: Fri Feb 20, 2009 3:35 pm
Location: Sri Lanka

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Google Feedfetcher and 4 guests