title: Socket Issue - Only first message read
body: <p>I am very new to sockets and was hoping someone could help me. I had something working but it was not sending information very quickly so i have refactored and now cannot get back to anything which works. The issue seems to be that only the first message that is published is read and then the  receiver sits on <code>client = listener.accept();</code> even though im pretty sure the sender is still sending messages</p>
  
  <p>Can anyone see what i might be doing wrong here please?</p>
  
  <p>Thanks</p>
  
  <pre><code>  public class Sender {
          Socket server = null;
          DataInputStream inp = null;
          PrintStream outp = null;
  
          public Sender(){
              server = new Socket("127.0.0.1" , 3456);
              outp = new PrintStream(server.getOutputStream());
          }
  
          private void connectAndSendToServer(String message)  {
              outp = new PrintStream(server.getOutputStream());
              outp.print(message + "\n");
              outp.flush();
  
          }
      }
  </code></pre>
  
  <p>Receiver class</p>
  
  <pre><code>public class Receive{
  
  
      public String receiveMessage(int port) {
          String message= null;
          ServerSocket listener = null;
          Socket client = null;
          try{
              listener = new ServerSocket(port);
              client = listener.accept();         
              BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
              return br.readLine();
  
          }
          ...
          finally{
              try {
                  if(client!=null &amp;&amp; listener!=null){
                      client.close();
                      listener.close();
                  }
              } 
              catch (IOException e) {
  
              }
          }
          return message;
      }
  }
  </code></pre>