title: Android Telnet client send
body: <p>Hi i'm just starting android studio for the most part. i'm following <a href="https://examples.javacodegeeks.com/android/core/socket-core/android-socket-example/" rel="nofollow noreferrer">this</a> tutorial on setting up sockets trying to get familiar with things. i can compile and run the application in the tutorial but the server i'm trying to send data to is a telnet server. the server just sits and waits for specific strings to do specific things. how can i modify this code to send strings to the telnet server? please ignore any invalid indents in the code from pasting it.</p>
  
  <pre><code>package com.javacodegeeks.android.androidsocketclient;
  
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.net.InetAddress;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.EditText;
  
  public class Client extends Activity {
  
  private Socket socket;
  
  private static final int SERVERPORT = 23;
  private static final String SERVER_IP = "10.0.0.50";
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      new Thread(new ClientThread()).start();
  }
  
  public void onClick(View view) {
      try {
          EditText et = (EditText) findViewById(R.id.EditText01);
          String str = et.getText().toString();
          PrintWriter out = new PrintWriter(new BufferedWriter(
                  new OutputStreamWriter(socket.getOutputStream())),
                  true);
          out.println(str);
      } catch (UnknownHostException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } 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);
  
          } catch (UnknownHostException e1) {
              e1.printStackTrace();
          } catch (IOException e1) {
              e1.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>