title: How to get a server to send a client a message on connection?
body: <p>I am trying to write a basic client-server program to allow the client to traverse the files of the server. I wish to get the server to, on connection of the client, send a list of all the files in the current directory to the client. How would I go about doing this ? I have already created an array of all the filenames, and am trying to send these to the client it just sits in an infinite loop (as it is meant to !) and does nothing.</p>
  
  <p>Attempting to have the server send a message on connection of the client :</p>
  
  <pre><code>    DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  
  
      boolean found = false;
  
      //Read the data from the input stream
      for (int i=0;i &lt; fileList.length;i++) {
        outToClient.writeBytes(fileList[i].getName());
      }
  </code></pre>
  
  <p>And to have the server receive this :</p>
  
  <pre><code>//Prepare an object for reading from the input stream
  BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  
  //Read the data from the input stream
  sentence = inFromServer.readLine();
  </code></pre>
  
  <p>but doing this just makes the client sit in an infinite loop and do nothing.</p>
  
  <p>Help please?</p>