title: How can I keep the program running so that I can send multiple messages and end the program when the user enters "end"
body: <p>How can I keep the program running so that I can send multiple messages and end the program when the user enters &quot;end&quot;. As it is now when I get the &quot;Enter a message prompt&quot; for the second time I get a java.io.EOFException.</p>
  <pre><code>try{
              System.out.println(&quot;Client started&quot;);
              socket = new Socket(&quot;localhost&quot;, port);
              do {
                      
                  in = new DataInputStream(socket.getInputStream());                      
                  out = new DataOutputStream(socket.getOutputStream());           
                  sc = new Scanner(System.in);   
                 
                      
                  System.out.println(&quot;Enter a message: &quot;); 
                 
                  
                  String l1 = sc.nextLine();                                                               
                  out.writeUTF(l1);                                                                                
                  l2 = in.readUTF();
            
              
                  
                  System.out.println(&quot;From Server: &quot; + l2); 
                  
              }while(l2 != &quot;end&quot; || l2 != &quot;dne&quot;);
              
              
              System.out.println(&quot;Closing connection&quot;);
              in.close();                                                                                                 
                          sc.close();
              out.close();
              socket.close();
          }
          catch(IOException i)
          {
                  System.out.println(i);
          }
  }
  </code></pre>