title: Java Socket Sending Data
body: <p>I have created two classes one server and client, I send data via the socket input and output stream however cant send multiple messages?</p>
  
  <p>Server:</p>
  
  <pre><code>public class SOK_1_SERVER {
  
      public static void main(String[] args) throws Exception
      {
  
          SOK_1_SERVER Sever = new SOK_1_SERVER();
          Sever.run();
      }
  
      private void run() throws Exception {
          ServerSocket SRVSOCK = new ServerSocket(444);
          //Waits both client and server to accept and we return 
          //a socket
          Socket SOCK = SRVSOCK.accept();
          //Once accepted 
          InputStreamReader isr = new InputStreamReader(SOCK.getInputStream());
          BufferedReader br = new BufferedReader(isr);
  
          String message = br.readLine();
          System.out.println("I read: " + message + "from Client");
  
          if(message != null)
          {
              //Sending message back to client 
              PrintStream ps = new PrintStream(SOCK.getOutputStream());
              ps.println("Message Received");
              ps.println("Send from Server");
          }
      }
  }
  </code></pre>
  
  <p>Client </p>
  
  <pre><code>public class SOK_1_CLIENT {
  
      public static void main(String[]args) throws Exception
      {
          SOK_1_CLIENT client = new SOK_1_CLIENT();
          client.run();
      }
  
      private void run() throws Exception {
          Socket SOCK = new Socket("localhost",444);
          PrintStream ps = new PrintStream(SOCK.getOutputStream());
          ps.println("Hello to Server from client");
  
          InputStreamReader ir = new InputStreamReader(SOCK.getInputStream());
          BufferedReader br = new BufferedReader(ir);
  
          String message = br.readLine();
  
          System.out.println(message);
  
      }
  
  }
  </code></pre>
  
  <p>It only outputs message received however I think its because I need to have a loop to keep checking for new messages however not sure as I have just started this looking into sockets.</p>