content: package com.example.administrator.webot;
  
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.net.Socket;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  
  public class MySocketClient {
  
      private static final String TAG = "TAG";
      private static final String HOST = "192.168.23.1";
      private static final int PORT = 9999;
      private PrintWriter printWriter;
      private BufferedReader in;
      private ExecutorService mExecutorService = null;
      private String receiveMsg;
  
  
      protected void onCreate() {
  
          mExecutorService = Executors.newCachedThreadPool();
      }
  
      public void connect() {
          mExecutorService.execute(new connectService());
      }
  
      public void send(String sendMsg) {
          mExecutorService.execute(new sendService(sendMsg));
      }
  
      public void disconnect() {
          mExecutorService.execute(new sendService("0"));
      }
  
      private class sendService implements Runnable {
          private String msg;
  
          sendService(String msg) {
              this.msg = msg;
          }
  
          @Override
          public void run() {
              printWriter.println(this.msg);
          }
      }
  
      private class connectService implements Runnable {
          @Override
          public void run() {
              try {
                  Socket socket = new Socket(HOST, PORT);
                  socket.setSoTimeout(60000);
                  printWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                          socket.getOutputStream(), "UTF-8")), true);
                  in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
                  receiveMsg();
              } catch (Exception e) {
                  Log.e(TAG, ("connectService:" + e.getMessage()));
              }
          }
      }
  
      private void receiveMsg() {
          try {
              while (true) {
                  if ((receiveMsg = in.readLine()) != null) {
                      Log.d(TAG, "receiveMsg:" + receiveMsg);
  
                  }
              }
          } catch (IOException e) {
              Log.e(TAG, "receiveMsg: ");
              e.printStackTrace();
          }
      }
  }
  