Networking from emulator instance and development machine

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Networking from emulator instance and development machine

Postby p4squ1 » Sun Oct 18, 2009 5:08 pm

Hi all! I'm a newbie on programming with android and I have the following problem:

I don't be able to connect the emulator's instance with my dev machine. In the emulator's instance is configured a client that have to connect on UDP with a server that running in my dev machine. The client is setted to communicate on address 10.0.2.2(my "127.0.0.1" dev machine) on port 4444. The server is listening on address 127.0.0.1 on port 4444. The client send the packet, but the server don't receive them. What are the problem???

I'm grateful who will help me!! PLEASE!!
p4squ1
Freshman
Freshman
 
Posts: 8
Joined: Fri May 15, 2009 10:18 pm
Location: Italy

Top

Postby TuxBobble » Wed Dec 30, 2009 7:39 pm

I am not going to be able to help you, as I am new to Android development as well.

Unless the AVD has a restriction on networking (I would hope not but I don't know for sure) I would suggest posting your source code, or at least the parts that you're having trouble with, so that we can look and see what might be wrong.

I am going to be working on networking to a server as well, but I haven't yet started my Android development, just refreshing myself in Java first.

So please, when you have a question like "why doesn't it work?" attach code so that we may be able to help you understand what is wrong with it, and reply effectively.
TuxBobble
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Dec 30, 2009 7:36 pm

Postby DMacATTACK » Thu Dec 31, 2009 6:40 pm

Although I am just starting with Android Development, I have done quite a bit of work with socket programming, so I'll try to help.

There are a few steps you could follow to remedy your problem:
1) Make sure your router is set up to do port forwarding (log into your router, and configure port 4444 for UDP).
2) Try 127.0.0.1 on your emulator client
3) Change your server to accept any IP/Port
4) If its possible use TCP

If all else fails, its probably your code, and like TuxBobble said, no one can help without posted code.
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Postby TuxBobble » Fri Jan 01, 2010 7:21 am

DMacATTACK wrote:Although I am just starting with Android Development, I have done quite a bit of work with socket programming, so I'll try to help.

There are a few steps you could follow to remedy your problem:
1) Make sure your router is set up to do port forwarding (log into your router, and configure port 4444 for UDP).
2) Try 127.0.0.1 on your emulator client
3) Change your server to accept any IP/Port
4) If its possible use TCP

If all else fails, its probably your code, and like TuxBobble said, no one can help without posted code.


DMacATTACK, well said with your suggestions. However, I'd like to point out that if you're using 127.0.0.1 or "localhost" as your address, you shouldn't need to worry about #1. When looking for "localhost" your computer generally does not look outward toward routers. Unless I'm mistaken, the router shouldn't be an issue if using localhost. Obviously if you want to connect from one computer to another, however, the router issue can and likely will come up.

DMac, since you said you have good experience with Socket programming, I'd like to ask--do you have any recommendations for learning Socket programming? I'm refreshing myself on Java these days but I've only done some very minimal Socket work, all in C.

Also, you might not have any answers on this one since you've just begun Android development, but are you aware of any distinct differences between the Java and Android imported Socket classes? I'm assuming I could use either one when programming for Android, but I haven't quite figured out the Android libraries yet, haha.

Anyway, to the OP, please post some code so we can discuss/comment about it--I'd love to help if possible, but can't do much without seeing what you've tried.
TuxBobble
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Dec 30, 2009 7:36 pm

Postby DMacATTACK » Mon Jan 04, 2010 5:01 am

TuxBobble wrote:DMacATTACK, well said with your suggestions. However, I'd like to point out that if you're using 127.0.0.1 or "localhost" as your address, you shouldn't need to worry about #1. When looking for "localhost" your computer generally does not look outward toward routers. Unless I'm mistaken, the router shouldn't be an issue if using localhost. Obviously if you want to connect from one computer to another,
however, the router issue can and likely will come up.


I understand where you're coming from, but I try to give the most full proof answer possible, because it is possible for a computer to have multiple IP's, which can cause 127.0.0.1 to cause problems. Also without knowing the Computer/Router settings or even OS its always best to keep it perfectly uniform before you go playing with different things.

TuxBobble wrote:DMac, since you said you have good experience with Socket programming, I'd like to ask--do you have any recommendations for learning Socket programming? I'm refreshing myself on Java these days but I've only done some very minimal Socket work, all in C.

Also, you might not have any answers on this one since you've just begun Android development, but are you aware of any distinct differences between the Java and Android imported Socket classes? I'm assuming I could use either one when programming for Android, but I haven't quite figured out the Android libraries yet, haha.

Anyway, to the OP, please post some code so we can discuss/comment about it--I'd love to help if possible, but can't do much without seeing what you've tried.


Hmmm recommendations...
Learn what the protocols are, and how they work. Then Synchronous UDP is a good place to start, then TCP, then work your way into Asynchronous TCP. Each one has its own pros and cons, but this is the best learning order in my opinion.

Unfortunately I don't have much knowledge with respect to the Android vs. Java libraries, we're probably going to be on the same path.
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests