title: Select thread to interact with Java
body: <p>So I have a socket situation where I have a multithread server that receive X number of connections and manage all of them (I use this code to base mine: <a href="http://www.java2s.com/Code/Java/Network-Protocol/AmultithreadedSocketServer.htm" rel="nofollow">http://www.java2s.com/Code/Java/Network-Protocol/AmultithreadedSocketServer.htm</a>). That's not completely my code but I used that as a base for the multithreading:</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  public class EchoServer {
    public static void main(String[] args) throws Exception {
      ServerSocket m_ServerSocket = new ServerSocket(12111);
      int id = 0;
      while (true) {
        Socket clientSocket = m_ServerSocket.accept();
        ClientServiceThread cliThread = new ClientServiceThread(clientSocket, id++);
        cliThread.start();
      }
    }
  }
  
  class ClientServiceThread extends Thread {
    Socket clientSocket;
    int clientID = -1;
    boolean running = true;
  
    ClientServiceThread(Socket s, int i) {
      clientSocket = s;
      clientID = i;
    }
  
    public void run() {
      System.out.println("Accepted Client : ID - " + clientID + " : Address - "
          + clientSocket.getInetAddress().getHostName());
      try {
        BufferedReader   in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        PrintWriter   out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
        while (running) {
          String clientCommand = in.readLine();
          System.out.println("Client Says :" + clientCommand);
          if (clientCommand.equalsIgnoreCase("quit")) {
            running = false;
            System.out.print("Stopping client thread for client : " + clientID);
          } else {
            out.println(clientCommand);
            out.flush();
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  </code></pre>
  
  <p>The problem is that all those clients connected to me are waiting a response from the user which provide that response using keyboard input (BufferedReader SYSTEM_IN = new BufferedReader(new InputStreamReader(System.in)); )  But I need to list all the threads that I have opened and select manually the one that I want to interact with. How can I do that??</p>
  
  <p>So for example to the first socket I want to send <code>foo</code> and <code>faa</code> to the second. </p>