Socket communication failing in eclipse
<p>Am trying to develop a simple socket communication between my phone and a PC. I have enabled the ineternet-uses permission but it still gives a java.net.connectionException error. Am developing the application in eclipse and I have tried setting the eclipse network connections to both native and proxy but it still is failing to connect. Could someone please point me in the right direction?</p>

<p>Both the PC and the emulator are in the same network.
This is the code I am trying to execute:
Client side : Android app :
    public class AndyActivity extends Activity {
    /** Called when the activity is first created. */
    private TextView serverIp;
    private Button connectPhones;
    private boolean connected=false;
    private String serverIpAddress="192.16.11.12";
    private Handler handler = new Handler();</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);      
connectPhones = (Button) findViewById(R.id.button1);
    serverIp = (TextView) findViewById(R.id.textView1);                 
    connectPhones.setOnClickListener(connectListener);
}
private OnClickListener connectListener = new OnClickListener(){
    @Override
    public void onClick(View v){
        serverIp.setText("lovely");
        if(!connected){
            serverIpAddress = serverIp.getText().toString();
            if (!serverIpAddress.equals("")) {
                Thread cThread = new Thread(new ClientThread());
                cThread.start();
            }

        }
    }
};

public class ClientThread implements Runnable {

public void run() {
        try {
            Log.d("ClientActivity", "C: Starting");
            //InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
            Log.d("ClientActivity", "C: Connecting...");
            int SERVERPORT = 9191;
        //    Socket socket = new Socket(serverAddr,SERVERPORT );

            Socket socket = new Socket("192.16.11.12",9192);
            Log.d("ClientActivity", "C: Connected");
            connected = true;
            while (connected) {
                try {
                    Log.d("ClientActivity", "C: Sending command.");
                    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket
                                .getOutputStream())), true);
                        // where you issue the commands
                  //      out.println("Hey Server!");
                        Log.d("ClientActivity", "C: Sent.");
                } catch (Exception e) {
                    Log.e("ClientActivity", "S: Error", e);
                }
            }
            socket.close();
            Log.d("ClientActivity", "C: Closed.");
        } catch (Exception e) {
            Log.e("ClientActivity", "C: Error", e);
            connected = false;
        }
    }

}
</code></pre>

<p>}</p>

<p>Server side:</p>

<pre><code>public class server1 {
  public static void main (String [] args ) throws IOException {
    // create socket
    ServerSocket servsock = new ServerSocket(9191);
    while (true) {
      System.out.println("Waiting...");

      Socket sock = servsock.accept();
      System.out.println("Accepted connection : " + sock);

      System.out.println("ok");
      sock.close();
      }
    }
}
</code></pre>
