title: How to Create A TelnetClient Connection pooling
body: <blockquote>
    <p>Blockquote</p>
  </blockquote>
  
  <p>I am trying to implement cusotm connection pooling for TelnetClient connections but getting some challenge......</p>
  
  <p>Step 1 : I have created a connection successfully
  Step 2 : I have tried to execute a command using above connection 
  successfully
  Step 3: but with the same connection as I tried to execute another command 
  than I am getting bothe the response(step 2 &amp; step 3) response and It's 
  seems as I am using the same connection and I did not closed it so the data<br>
  are present in connection input &amp; output streams.</p>
  
  <p>Can be reset inputSteam of the connection so that I can only have the 
  current command resposne in it.</p>
  
  <p>Is there is anyother opensource api for TelnetClient connection pooling?</p>
  
  <p>I dont have much experience in network and socket programming any help 
  would be highly appreciate!!</p>
  
  <blockquote>
    <p>Blockquote</p>
  </blockquote>
  
  <pre><code> //Method is used to create a connection 
   private TelnetClient createTelnetConnection() throws SocketException, 
  IOException {
      TelnetClient telnetConnection = new TelnetClient();
      telnetConnection.connect(127.0.0.1, 6300);
      telnetConnection.setConnectTimeout(240000);
      telnetConnection.setSoTimeout(300000);
      return telnetConnection;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>//This method is used to execute command using connection
  public String executeCommand(String command, TelnetClient connection) throws InterruptedException,
      IOException {
      OutputStream outputstream = null;
      InputStream inputstream = null;
      String response = "";
  
      outputstream = connection.getOutputStream();
      outputstream.write(command.getBytes());
      outputstream.flush();
  
      inputstream = connection.getInputStream();
  
      response = getStringFromInputStream(inputstream);
      return response;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>  private String getStringFromInputStream(InputStream inputStream) throws 
     IOException {
        BufferedReader bufferReader = null;
        StringBuilder responseString = new StringBuilder();
        String line;
        bufferReader = new BufferedReader(new InputStreamReader(inputStream));
        String response = null;
        while ((line = bufferReader.readLine()) != null) {
          responseString.append(line);
          break;
  
      }
      return responseString.toString();
   }
  </code></pre>