1 Replies - 1090 Views - Last Post: 03 April 2013 - 01:01 PM

#1 GaryDoo  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 131
  • Joined: 10-February 13

How to test for data received - Server/Client

Posted 02 April 2013 - 09:14 AM

Hi Folks,

I am writing an app that involves Client -> Server -> Client communication. 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 :bigsmile: .

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);

		LocationManager mlocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		LocationListener mlocationListener = new MyLocationListener();

		mlocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
				0, 0, mlocationListener);

		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();		
	}


Is This A Good Question/Topic? 0
  • +

Replies To: How to test for data received - Server/Client

#2 GaryDoo  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 131
  • Joined: 10-February 13

Re: How to test for data received - Server/Client

Posted 03 April 2013 - 01:01 PM

I sorted this myself
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1