title: Threaded TCP connection - Android
body: <p>I'm trying to make an Android app that will send some packets of data to an embedded device.
  Since my embedded device is not supporting UDP datagram protocol, I would like to simulate it using sync TCP.</p>
  
  <p>That being said, a response string from the device is not needed, so I would like to disconnect the TCP socket as soon as the data is sent from my app.</p>
  
  <p>I would be grateful if someone could outline how to make a Thread that would perform the connection and close the socket if no data is received within some timeframe.</p>
  
  <p>My current code is simple:</p>
  
  <pre><code>    try {
          Socket s = new Socket("localhost",12345);
  
          //outgoing stream redirect to socket
          OutputStream out = s.getOutputStream();
  
          PrintWriter output = new PrintWriter(out);
          output.println("Hello Android!");
          BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
  
          //read line(s)
          String st = input.readLine();
          . . .
          //Close connection
          s.close();
  
  
  } catch (UnknownHostException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
  </code></pre>
  
  <p>Thank you in advance!!!</p>