title: Java Simple Client/Server read/write
body: <p>I`m trying to make a Simple chat between the Client and Server or 2 way Communication</p>
  
  <p>The Problems I`m facing is if I Keep Entering new text on any one side then that does not show up... only the first text Entered Shows up.</p>
  
  <p>Both Server and Client side quit after a text has been Entered from server side once and once from client side.</p>
  
  <pre><code>Server
  import java.net.*;
  import java.io.*;
  import java.util.Scanner;
  public class Server {
      ServerSocket server;
      Socket s;
      InputStream input;
      OutputStream out;
      Scanner in=new Scanner(System.in);
      BufferedReader br;
      PrintWriter pw;
      String str1;
      String str2;
      public void create() throws Exception{
         server=new ServerSocket(40000);
         System.out.println("Begin :) Server");
         s=server.accept();
         input=s.getInputStream();
         out=s.getOutputStream();
         br=new BufferedReader(new InputStreamReader(input));
         pw=new PrintWriter(out);
         t1.start();
         t2.start();
      }
      Thread t1=new Thread(new Runnable(){
          @Override
          public void run (){
           str1=in.nextLine();
           pw.println(str1);
           pw.flush();
          }
      });
      Thread t2=new Thread(new Runnable(){
          @Override
          public void run(){
             try{
              str2=br.readLine();
             }catch(Exception e){}
             System.out.println(str2);
          }
      });
      public static void main(String[] args) throws Exception{
         Server s=new Server();
         s.create();       
      }
  }
  
  
  Client
  import java.util.Scanner;
  import java.net.*;
  import java.io.*;
  public class Client {
      Socket s;
      InputStream input;
      OutputStream out;
      BufferedReader br;
      PrintWriter pw;
      Scanner in;
      String str1;
      String str2;
      public void create() throws Exception{
          s=new Socket("localhost",40000);
          System.out.println("Begin :) Client");
          input=s.getInputStream();
          out=s.getOutputStream();
          br=new BufferedReader(new InputStreamReader(input));
          pw=new PrintWriter(out);
          in=new Scanner(System.in);
          t1.start();
          t2.start();
      }
      Thread t1=new Thread(new Runnable(){
          @Override
          public void run(){
               str1=in.nextLine();
               pw.println(str1);
               pw.flush();
          }
      });
      Thread t2=new Thread(new Runnable(){
          @Override
          public void run(){
              try {
                  str2=br.readLine();
              } catch (Exception e) {}   
              System.out.println(str2);
          }
      });
      public static void main(String[] args) throws Exception {
          Client c=new Client();
          c.create();
      }
  }
  </code></pre>
  
  <p>Is there a way to achieve 2 way Communication without using threads?</p>