title: android open socket crashing on device, works on AVD
body: <p>i try creating client-server app using socket.
  i already succeed doing that with the AVD and run both server and client on my pc machine.
  but when i try make it work in same Wifi network on my device, the app just crash.</p>
  
  <p>yes, i'm using seperate thread for the connection
  and already added the use of Internet to the manifest.</p>
  
  <p>here is some code...</p>
  
  <p>the client thread:</p>
  
  <pre><code>package com.mainlauncher;
  
  import java.io.*;
  import java.net.*;
  
  public class ConnectionThread extends Thread {
  
  private static final int SERVERPORT = 7777;
  private static final String SERVERADDRESS = "My-PC";
  private Socket socket;
  private DataInputStream in;
  private DataOutputStream out;
  
  @Override
  public void run() {
      super.run();
      open();
      close();
  }
  
  void open(){
      try{
          socket = new Socket(SERVERADDRESS,SERVERPORT);
          in = new DataInputStream(socket.getInputStream());
          out = new DataOutputStream(socket.getOutputStream());
      }
      catch(IOException e){}
  }
  
  void close(){
      try {
          if(in!=null)
              in.close();
          if(out!=null)
              out.close();
          if(socket!=null)
              socket.close();
      } 
      catch (IOException e) {}
      socket=null;
  
  }
  
  
  }
  </code></pre>
  
  <p>the Server side main:</p>
  
  <pre><code>import java.io.IOException;
  import java.net.*;
  
  
  public class Main {
  
  public static void main(String[] args) {
      int port = 7777;
      new Main().handleClients(port);
  }
  
  private void handleClients(int port) {
      ServerSocket serverSocket = null;
      try{
          serverSocket = new ServerSocket(port);
          System.out.println("Server is ready...");
          for(int i=1; ; i++){
              Socket socket = serverSocket.accept();
              ServerThread thread = new ServerThread(i,socket);
              System.out.println(i + " Connected");
              thread.run();
          }
      }
      catch (Exception e){
          System.err.println(e.getMessage());
      }
      finally{
          if(serverSocket != null){
              try{ serverSocket.close(); }
              catch(IOException x){}
          }
  
      }
  
  
  }
  
  }
  </code></pre>
  
  <p>and the ServerThread:</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  
  
  public class ServerThread extends Thread {
  
  private int serverIndex;
  private Socket socket;
  private DataOutputStream out;
  private DataInputStream in;
  
  public ServerThread (int serverIndex, Socket socket){
      this.serverIndex = serverIndex;
      this.socket = socket;
  }
  
  @Override
  public void run() {
      super.run();
  
      try {
          in = new DataInputStream(socket.getInputStream());
          out = new DataOutputStream(socket.getOutputStream());
      } catch (IOException e) {
          System.out.println(serverIndex + " Disconnected");
      }
  
      finally{
          try {
              in.close();
              out.close();
              socket.close();
          } catch (IOException e) {}
      }
  }
  }
  </code></pre>
  
  <p>i tried looking for answers here \ google etc...
  nothing helped.
  there is no firewall or anything to block the incoming connection on my pc.</p>
  
  <p>any ideas anyone?</p>
  
  <p>thanks,
  Lioz</p>