0

Hi Folks,

I am writing an app that involves Client -> Server -> Client communication (one way traffic). I have my data transmitted from client A to the server, simple to test, just print to console, however, I'm trying to test to see if the data has been sent on to the next client. I have tried a text view, nothing is displaying in this view however, now I don't know if that's because the data hasn't arrived or indeed because I've coded it wrong. I'm not very experienced in android.

I've attached my code below, if anyone can help I would really appreciate it.

Regards,
Gary

public class Parent extends Activity {

    private Socket s;
    private PrintWriter p;
    String location;
    double Platitude, Plongitude;
    double Clatitude, Clongitude;
    double distance;

    public void onCreate(Bundle savedInstanceState)

    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.parent);

        Thread rec = new Thread(new Runnable() {

            public void run() {

                // TODO Auto-generated method stub
                try { 

                    s = new Socket("192.168.1.2", 1980);

                    InputStream fromServer = s.getInputStream();

                    while (s.isConnected()) {

                        Scanner r = new Scanner(fromServer);

                        if(r.hasNextLine())
                        {
                            location = r.nextLine();
                        }

                        TextView myTextview = (TextView) findViewById(R.id.dist);
                        myTextview.setText(location);

                    }

                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        rec.start();       
    }
1
Contributor
1
Reply
22
Views
5 Years
Discussion Span
Last Post by DJ-DOO
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.