title: Parse text file content onto client window using java rmi protocol?
body: <p>Am new to RMI technology, and was struggling with parsing file content onto client command window after the user is connected to RMI server. </p>
  
  <p>The problem is that I can can read the file but it only read the first line not the rest of the file content. Can someone view my code and see where am wrong.</p>
  
  <h2>interface</h2>
  
  <pre><code>/**
   * The purpose of this interface is to declare a set of remote methods 
   * and each remote method must declare RemoteException in its throws clause 
   * Here we are simple making this available to remote accesseser 
   * 
   * A remote interface defines a remote service.
   * The interface java.rmi.remote extend not interface or methods,
   * it is a marker interface which distinguishes remote interfaces from non-remote interfaces.*/
  
   import java.rmi.Remote;
   import java.rmi.RemoteException;
  
   public interface RemoteInterface extends Remote {
  
      /**
       * method returns a String message to its caller
       * @param str :value of String*/
       public String sayHello(String str) throws RemoteException;
       public String displayQuestions() throws RemoteException;
   }
  </code></pre>
  
  <h2>Remote Object</h2>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.rmi.RemoteException;
  
   //remote object
   public class HelloImpl implements RemoteInterface {
  
  @Override
  public String sayHello(String str) throws RemoteException {
      return "Hello: " + str;
  }
  
  @Override
  public String displayQuestions() throws RemoteException {
  
      try {
          BufferedReader br = new BufferedReader(new FileReader("questions.txt"));
          while(true){
              String line = br.readLine();
              if(line == null) break;
          return line;
          }
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return null;
      }
  }
  </code></pre>
  
  <h2>RMI Server</h2>
  
  <pre><code> /**
   * The purpose of this class is to implement the server. 
   * This class will have a main() method that:-
   * 1- creates an instance(object of remote object) of the remote object implementation,
   * 2- then exports the remote object
   * 3- then register the remote object with a Java RMI registry
   * */
  
      import java.rmi.registry.LocateRegistry;
      import java.rmi.registry.Registry;
      import java.rmi.server.UnicastRemoteObject;
  
  //RMI Server
  public class HelloServer {
  
  public HelloServer() {
  }
  
  public static void main(String[] args) {
      try {
  
          //Create an instance of the remote object
          //here remoteObj is an instance of remote object 'HelloImpl'
          HelloImpl remoteObj = new HelloImpl();
  
          //To Export the remote object, we will use 'UnicastRe...exportObject(remoteObj, TCPPortNo)' method
          //When you export a remote object, you make that object available to accept incoming calls from clients
          //If you pass a zero to the method, the default TCP port number 1099 is used.
          //Note that the exportObject() method will return a stub, which is a term used to describe a proxy class
          //The stub class is a key to make remote object available for remote invocation
          RemoteInterface stub = (RemoteInterface) UnicastRemoteObject
                  .exportObject(remoteObj, 0);
          // Bind the remote object's stub in the registry
          // create a registry instance, this will get me the handle to the registry
          Registry registry = LocateRegistry.getRegistry();
          registry.rebind("nameOfRObj", stub); // here we bind an instance of the object in the registry 
          System.out.println("Hello Server is ready to listen...");
  
      } catch (Exception e) {
          System.err.println("Server exception thrown" + e.toString());
          e.printStackTrace();
      }
  }
  
    }
  </code></pre>
  
  <h2>RMI Client</h2>
  
  <pre><code> import java.rmi.registry.LocateRegistry;
   import java.rmi.registry.Registry;
   import java.util.ArrayList;
   import java.util.List;
  
  
   public class HelloClient {
  
  public HelloClient(){}
  
  public static void main(String[] args){
  
      //String mood = inProfit() ? "happy" : "sad";
      //if args length is lessthan 1, then assign the value localHost to field hostName
      //otherwise, assign args[0] thats passed to hostName
      String hostName = (args.length &lt; 1) ? "localHost" : args[0];
      try {
          //Locate a host from the registry mechanism.
          Registry registry = LocateRegistry.getRegistry(hostName);
          //look up the remote object by its name
          RemoteInterface stub = (RemoteInterface) registry.lookup("nameOfRObj"); 
  
  
  
          String name = stub.sayHello("Betty");
          System.out.println("Got info from server: " + " " + name);
  
          List&lt;String&gt; list =  new ArrayList&lt;String&gt;();
          list.add(stub.displayQuestions());
  
          for(String line : list)
          System.out.println("Content" + line);
  
      } catch (Exception e) {
          System.out.println("Client exception thrown: " + e.toString());
          e.printStackTrace();
      }
  }
  
  }
  </code></pre>
  
  <h2>Text File Content</h2>
  
  <pre><code>Questions database:
  Q1: (A + B)*(A+B)
  1. A*A + B*B
  2. A*A +A*B + B*B
  3. A*A +2*A*B + B*B  
  Q2: (A + B)*(A - B)
  1. A*A + 2*B*B
  2. A*A - B*B 
  3. A*A -2*A*B + B*B
  Q3: sin(x)*sin(x) + cos(x)*cos(x)
  1. 1 
  2. 2
  3. 3
  </code></pre>
  
  <h2>current Result</h2>
  
  <pre><code>D:\rmi&gt;java HelloClient
  Got info from server:  Hello: Betty
  ContentQuestions database:
  </code></pre>
  
  <h2>Expected Result</h2>
  
  <p>One question should appear at a time on client window, when he/she answer the first question then the second question  appears and then third and the final score for answering the correct question.</p>
  
  <p>for example on client window:<br>
    Please select the correct answer<br>
    Q1: blalalala?<br>
    1: A<br>
    2: b <br>
    3: c<br>
    input: a<br></p>
  
  <p>Please select the correct answer<br>
    Q2: blalalala?<br>
    1: A<br>
    2: b <br>
    3: c<br>
    input: b <br>
    .... <br></p>
  
  <p>Final Score 2 out possible 3 Q<br>
   Goodbye!<br></p>