Server with Multiple Android Clients
I'm writing a server which accepts multiple android clients. The server listens on a socket, and the clients send their location data over to the server, and the server replies back. The problem is that when the connection between server and client is established, the method 'onLocationChanged' is not reached. However, as I stop the server, the onLocationChanged method work (obviously not sending data to the server, just displayin data locally). Here is what I did:

The Server Class:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class NewClass1 implements Runnable {

    private int ID;
    

     private Socket connection;

     public static void main(String[] args)
     {
         int port = 1234;
         int count = 0;

         try
         {
             ServerSocket serverSocket = new ServerSocket(port);
             System.out.println("Server Initialized");
             while (true)
             {
                 Socket connection = serverSocket.accept();
                 Runnable runnable = new NewClass1(connection, ++count);
                 Thread thread = new Thread(runnable);
                 thread.start();
             }
         }
         catch (Exception e)
         {
             System.out.println("opening socket failed");
         }
     }


     NewClass1(Socket s, int i)
     {
         this.connection = s;
         this.ID=i;

     }

     public void run()
     {
         String line;
         BufferedReader in = null;
         PrintWriter out = null;
         try
         {
            in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
            out = new PrintWriter(connection.getOutputStream());
         }
         catch(Exception e)
         {
             System.out.println("Readers and Writers failed");
             System.exit(-1);
         }

         while(true)
         {
             try
             {
                 line = in.readLine();
                 out.println("Success");
                 System.out.println(line);

             }
             catch(Exception e)
             {
                 System.out.println("Failed");
             }
         }
     }


}


and the Client activity:


package com.servertest;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import java.io.*;
import java.net.*;

public class MainActivity extends Activity {
    
	TextView tview;
	BufferedReader in;
	Socket socket;
	private LocationManager lm;
    private LocationListener locationListener;

    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	tview = new TextView(this);    
    	
    	try
    	{
        	socket = new Socket("10.0.2.2", 1234);
        	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
        	out.println("Connection Established");
        	        	
        }
    	catch (Exception e)
    	{ 
    		tview.setText(e.toString());
    	}
    	
        try 
        { 
        	in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        	
        }
        catch (Exception e)
        { 
        	tview.setText(e.toString());
        }
        
        setContentView(tview);
        super.onCreate(savedInstanceState);
        
        lm = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);    
    
        locationListener = new MyLocationListener();
    
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);  
        
  	    try
  	    {
  	        String line = in.readLine();
  	    } 
  	    catch (IOException e) 
  	    {
  	         System.exit(-1);
  	    }
        
    }
    
    private class MyLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location loc) {
            
        if (loc != null) {
            	
            	PrintWriter out;
            	
				try 
				{
					out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
					out.println("Location test");
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
				
                Toast.makeText(getBaseContext()," Locationchanged : Lat: " + loc.getLatitude() + 
                    " Lng:  " + loc.getLongitude(), 
                    Toast.LENGTH_SHORT).show();
                
                try
          	    {
                	String line = in.readLine();
                	
          	    } 
                catch (Exception e)
                {
                	System.out.println("reading  failed");
                	
                }
               
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStatusChanged(String provider, int status, 
            Bundle extras) {
            // TODO Auto-generated method stub
        }
    }        

    
}


Can anyone tell me what I'm doing wrong? 
Server with Multiple Android Clients
===

I'm writing a server which accepts multiple android clients. The server listens on a socket, and the clients send their location data over to the server, and the server replies back. The problem is that when the connection between server and client is established, the method 'onLocationChanged' is not reached. However, as I stop the server, the onLocationChanged method work (obviously not sending data to the server, just displayin data locally). Here is what I did:

The Server Class:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class NewClass1 implements Runnable {

    private int ID;
    

     private Socket connection;

     public static void main(String[] args)
     {
         int port = 1234;
         int count = 0;

         try
         {
             ServerSocket serverSocket = new ServerSocket(port);
             System.out.println("Server Initialized");
             while (true)
             {
                 Socket connection = serverSocket.accept();
                 Runnable runnable = new NewClass1(connection, ++count);
                 Thread thread = new Thread(runnable);
                 thread.start();
             }
         }
         catch (Exception e)
         {
             System.out.println("opening socket failed");
         }
     }


     NewClass1(Socket s, int i)
     {
         this.connection = s;
         this.ID=i;

     }

     public void run()
     {
         String line;
         BufferedReader in = null;
         PrintWriter out = null;
         try
         {
            in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
            out = new PrintWriter(connection.getOutputStream());
         }
         catch(Exception e)
         {
             System.out.println("Readers and Writers failed");
             System.exit(-1);
         }

         while(true)
         {
             try
             {
                 line = in.readLine();
                 out.println("Success");
                 System.out.println(line);

             }
             catch(Exception e)
             {
                 System.out.println("Failed");
             }
         }
     }


}


and the Client activity:


package com.servertest;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import java.io.*;
import java.net.*;

public class MainActivity extends Activity {
    
	TextView tview;
	BufferedReader in;
	Socket socket;
	private LocationManager lm;
    private LocationListener locationListener;

    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	tview = new TextView(this);    
    	
    	try
    	{
        	socket = new Socket("10.0.2.2", 1234);
        	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
        	out.println("Connection Established");
        	        	
        }
    	catch (Exception e)
    	{ 
    		tview.setText(e.toString());
    	}
    	
        try 
        { 
        	in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        	
        }
        catch (Exception e)
        { 
        	tview.setText(e.toString());
        }
        
        setContentView(tview);
        super.onCreate(savedInstanceState);
        
        lm = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);    
    
        locationListener = new MyLocationListener();
    
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);  
        
  	    try
  	    {
  	        String line = in.readLine();
  	    } 
  	    catch (IOException e) 
  	    {
  	         System.exit(-1);
  	    }
        
    }
    
    private class MyLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location loc) {
            
        if (loc != null) {
            	
            	PrintWriter out;
            	
				try 
				{
					out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
					out.println("Location test");
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
				
                Toast.makeText(getBaseContext()," Locationchanged : Lat: " + loc.getLatitude() + 
                    " Lng:  " + loc.getLongitude(), 
                    Toast.LENGTH_SHORT).show();
                
                try
          	    {
                	String line = in.readLine();
                	
          	    } 
                catch (Exception e)
                {
                	System.out.println("reading  failed");
                	
                }
               
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStatusChanged(String provider, int status, 
            Bundle extras) {
            // TODO Auto-generated method stub
        }
    }        

    
}


Can anyone tell me what I'm doing wrong? 