title: Server/client String[] array over Socket connection
body: <p>I'm trying to send a String[] over an open socket connection but it's doesn't work.
  I went to send an array from database and sending result set on client after a socket connection!</p>
  <h2>Server</h2>
  <pre><code>public class ServerConnectionHandler implements Runnable {
  
  private static String String;
  private Socket clientSocket;
  
  public ServerConnectionHandler(Socket clientSocket) {
      this.clientSocket = clientSocket;
  }
  
  public String[] toStringArray(ResultSet resultSet, String columnLabel) {
      LinkedList&lt;String&gt; resultList = new LinkedList&lt;String&gt;();
   
      try {
          while (resultSet.next()) {
              resultList.add(resultSet.getString(columnLabel));
          }
      } catch (SQLException e) {
          e.printStackTrace();
      }
   
      return resultList.toArray(new String[0]);
  }
      
  @Override
  public void run() {
  
      
      
  
      ResultSet val = null;
      System.out.println(&quot;Client &quot; + clientSocket.getInetAddress() + &quot;:&quot; + clientSocket.getPort() + &quot; has connected.&quot;);
      Mysql conn = new Mysql(&quot;****&quot;, &quot;root&quot;, &quot;&quot;,&quot;*****&quot;);
      val = conn.executeSelect(CONSTANT.QUERY_ALL);
      String[] mybytearray = toStringArray(val,&quot;real_url&quot;);
      
      try {
          PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
          BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
          
          String inputline, outputline;
          outputline = &quot;Connected to server...type in the console to interact!&quot;;
          out.println(outputline);
          
          
          while((inputline = in.readLine()) != null){
              outputline = &quot;Server echoes: &quot; + mybytearray;
              out.println(outputline);
          }
      }
      
      catch(Exception e) {
          System.out.println(&quot;Client &quot; + clientSocket.getInetAddress() + &quot;:&quot; + clientSocket.getPort() + &quot; has disconnected.&quot;);
      }
      
  }
  </code></pre>
  <p>}</p>
  <h2>Client</h2>
  <pre><code>public class ClientMain {
  
  private String host;
  private int port;
  
  public ClientMain(String host, int port) {
      this.host = host;
      this.port = port;
  }
  
  public void start() {
      try {
          Socket clientSocket = new Socket(host, port);
          PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
          BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
          
          String inputline, outputline;
              while((inputline = in.readLine()) != null){
                  System.out.println(inputline);
                  outputline = getUserInput();
                  out.println(outputline);
                  
              }
      } 
      
      catch (Exception e) {
          System.out.println(&quot;Server not running, shutting down...&quot;);
          System.exit(-1);
      } 
  }
  
  private static String getUserInput() {
      String s = &quot;&quot;;
      InputStreamReader isr; 
      BufferedReader br;
      try {
          isr = new InputStreamReader(System.in);
          br = new BufferedReader(isr);
          s += br.readLine();
          
      }
      catch(IOException e){
          e.printStackTrace();
          System.exit(-1);
      }
  
      return s;
  }
  </code></pre>
  <p>}</p>