title: Socket android client PC server
body: <p>I have problem to connect my android client to my PC Server
  here there are the codes</p>
  
  <p>-->PC SERVER:</p>
  
  <pre><code>public class Server {
  
  public static void main(String[] args) throws IOException, SQLException, ClassNotFoundException
  {
  
     ServerSocket server = new ServerSocket(4444);
  
     System.out.println("Waiting for clients to connect...");
  
     while (true)
     {
        Socket s = server.accept();
        InetAddress clientAddress = s.getInetAddress();
        System.out.println("Incoming connection from: " + clientAddress.getHostName() + "[" + clientAddress.getHostAddress() + "]");
  
        s.close();
     }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>--->ANDROID CLIENT:</p>
  
  <pre><code>public class Main extends Activity {
  
  Button b;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      b = (Button)findViewById(R.id.connect);
      b.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View arg0) {
  
              try {
                   Socket client = new Socket("10.0.2.2", 4444); //connect to server
  
                   client.close();   //closing the connection
  
                  } catch (UnknownHostException e) {
                   e.printStackTrace();
                  } catch (IOException e) {
                   e.printStackTrace();
              }
  
          }
  
      });
  
  }
  </code></pre>
  
  <p>When on my android device i click the button in my server program(PC) doesn't view device connect...why? i've tried to insert </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
  </code></pre>
  
  <p>into my AndroidManifest but when i click on button program crash
  Android device and PC are connected to same network(router DSL).</p>
  
  <p>Help me please</p>