title: How to send and receive strings through TCP connection using kotlin
body: <p>I have a TCP Server on Windows, and I want to send and receive text strings between the server and my Android device.</p>
  
  <p>I spent alot of time searching for an example using Kotlin but I didn't find any useful code, so I'm now only able to create the socket and connect.</p>
  
  <pre><code>fun connect() {
      try{
          val soc = Socket("192.168.1.5", 1419)
          val dout = DataOutputStream(soc.getOutputStream())
          dout.writeUTF("1")
  
          dout.flush()
          dout.close()
          soc.close()
      }
      catch (e:Exception){
          e.printStackTrace()
      }
  }
  </code></pre>