title: Cant read data from TCP Server with Android Client APP
body: <p>That is my program in java for my android app. I tried to create tcp connection with tcp server. I can connect to server with another applications so that i can send and receive from tcp server. With my code and with my program i can send messages to server very eazy, but i have troubles with receiving messages from server.</p>
  
  <pre><code>private  Socket socket;
  private  final int SERVERPORT = 6060;    
  private  final String SERVER_IP = "192.168.0.8";
  public  TextView tv;
  private PrintWriter out;
  private InputStream in;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      tv=(TextView)this.findViewById(R.id.textView1);
       new Thread(new ClientThread()).start();
  
  }   
  </code></pre>
  
  <p>Here is my problem i dont know how to receive strings or bytes from server. When i run my app on phone it closes the open window and say that program stop working. If i delete this section of code(public void ONCLICK2) i can transmit messages to server. </p>
  
  <pre><code>  public void   ONCLICK2(View view)  {
  
         try {
          in=socket.getInputStream();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
          byte array[]=new byte[1];
          try {
              int i=in.read(array);
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
  
    }
  </code></pre>
  
  <p>So please help me with that section of code. How can i receive string send from TCP server.</p>
  
  <pre><code>    public void onClick(View view) {
                  try {
                  EditText et = (EditText) findViewById(R.id.editText1);
                  String str = et.getText().toString();
  
                      out.println(str);
                      out.flush();
  
                  }catch (Exception e) {
                      e.printStackTrace();
                  }
              }
  
  
  class ClientThread implements Runnable {
  
       @Override
              public void run() {
  
                 try {
                     InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
  
                      socket = new Socket(serverAddr, SERVERPORT);
  
                      out = new PrintWriter(new BufferedWriter(
                              new OutputStreamWriter(socket.getOutputStream())),
                                      true);
  
  
  
             } catch (UnknownHostException e1) {
                       e1.printStackTrace();
           } catch (IOException e1) {
                      e1.printStackTrace();
                  }
  
           }
  
  }
  </code></pre>