Hi 

Did you add <uses-permission android:name="android.permission.INTERNET"
/> 
To your manifest file.

Try it works

Cheers
Ash
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Lorenz
Sent: 28 July 2009 18:15
To: Android Beginners
Subject: [android-beginners] Problem: connect to a server


Hi to everyone,
I want to connect my Android application to a server through a thread
but it doesn't work, as a matter of fact the server doesn't answer.
My code is:


import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import java.io.*;
import java.net.*;
import java.util.NoSuchElementException;


public class C extends Activity {
        private PrintWriter savedpoint;
        private Context context = this;
        private TextView statusField;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        F thread=new F(getFilesDir(),this,statusField);
        thread.start
();                                                //START THE THREAD
    }
}

                                    //THE THREAD THAT HAVE TO CONNECT TO
THE SERVER class F extends Thread{
        Context context;

        private final static String host = "10.0.2.2";
        private final static int port = 2111;


        F(Context context){this.context=context;}
        public void run()
        {

                try{

                Socket socket = null;
                PrintWriter out = null;
                InetAddress ip = InetAddress.getByName(host);
                socket = new Socket(ip,port);

                } catch (UnknownHostException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();}
        }
}
//THE SERVER is simple, it accepts a client at 2111 port ,when a client
is accepted, the server  report it on the shell with "CLient Connected".
//Furthermore, the server has already been tested with a normal client
and it perfectly works!

So, what can be the problem??with the port?with the host address??
if someone have done something like this or know what could be the
problem or have the time to test it please answer me!In case I can post
also the Server code that is very simple!
thank in advance



--~--~---------~--~----~------------~-------~--~----~
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