title: My simple Android app doesn't send data to a socket
body: <p>I have a simple Android app that is supposed to send some data to a server I have over socket with a given IP and port number. </p>
  
  <p>On my <code>onCreate()</code> I connect to the server. This part works:</p>
  
  <pre><code>// connect to the server
  clientThread = new ClientThread();
  thread = new Thread(clientThread);
  thread.start();
  </code></pre>
  
  <p>But the <code>sendMessage()</code> doesn't send any messages to the socket and I don't receive anything on my server. The function doesn't even show the log message so I don't know what is happening. What is the problem? How to fix it?</p>
  
  <pre><code>//TODO send data
                              clientThread.sendMessage(100);
  </code></pre>
  
  <p>Here is the socket thread class:</p>
  
  <pre><code>class myApp extends Activity{
  //....
  ClientThread clientThread;
  Thread thread;
  //....
  
  class ClientThread implements Runnable {
  
  private Socket socket;
  private BufferedReader input;
  
  @Override
  public void run() {
      InetAddress serverAddr = null;
      try {
          serverAddr = InetAddress.getByName(SERVER_IP);
      } catch (UnknownHostException e) {
          e.printStackTrace();
      }
      try {
          socket = new Socket(serverAddr, SERVERPORT);
          Log.i("Hello: Connected","Hello: Connected");
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  void sendMessage(int data) {
      try {
          if (null != socket) {
              PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),
                      true);
              out.println(data);
              Log.i("Hello Message sent","Hello sent: "+data+" to: "+ SERVER_IP+":"+SERVERPORT);
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  }
  }
  </code></pre>
  
  <p>My server-side receive (Java server):</p>
  
  <pre><code>public void run() {
      System.out.println("Got a new user!");
      InputStream inp;
  
      try {
          /* Get Data From Client */
          inp = socket.getInputStream();
          int data= inp.read();
          System.out.println(address+" "+ data);
  
          if (data!=0) {
              scoreboard.b1.y+=1;
              if (scoreboard.b1.y==scoreboard.MaxValue) {
                  System.out.println("HELLLOOOOOOO");
                  scoreboard.updateValue();
              }
              scoreboard.repaint();
          }
  
      } catch (IOException e) {
          return;
      }
      String line;
  }
  </code></pre>