Hi James,

Thanks a lot! I actually just figured it out as well and was about to
post my solution here.
http://developer.android.com/guide/developing/tools/emulator.html#emulatornetworking
So for anyone having a similar problem,

Basically 10.0.2.2 is the Android Emulator's alias to 127.0.0.1
The emulator does not understand when you specify "localhost"
So change the line:
Socket socket = new Socket("localhost", 5554);
to
Socket socket = new Socket("10.0.2.2", 5554);

Cheers!

On Oct 8, 4:26 pm, James Yum <[email protected]> wrote:
> Hi Android n00b,
>
> http://groups.google.com/group/android-developers/browse_thread/threa...
> <http://groups.google.com/group/android-developers/browse_thread/threa...>
> Cheers,
> James
>
>
>
> On Thu, Oct 8, 2009 at 12:57 PM, Android_n00b <[email protected]> wrote:
>
> > Hi,
>
> > I am trying to create a connection between a server socket program
> > written in C and an android client socket program. Now when I write a
> > regular java client program such as:
>
> > try
> > {
> >        Socket socket = new Socket("localhost", 5554);
> >        PrintWriter out = new PrintWriter(echoSocket.getOutputStream
> > (), true);
> > }
> > catch(Exception e)
> > {
> >              //................
> > }
> > out.println("Hello World");
>
> > This program works perfectly and my server.c file receives the
> > message.
> > However, when I try the same program with the Android Emulator, I get
> > an "Error:java.net.ConnectException: localhost/127.0.0.1:5554 -
> > Connection refused" I have tried different ports as well (8888, 3490).
> > This works perfectly with the regular Java project, but the moment I
> > write the same code in an Android project I get that error. I have
> > been stuck on this all day and am really getting frustrated :( Would
> > appreciate any help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to