title: Server Socket Keeps Reading Data Until I close Socket from Client In Java
body: <p>Im unable to get data in server from client using java
  Following is my server code :</p>
  
  <pre><code> public void UpdateClients() throws Exception{
  
      Socket socktmp=null;
  
      try
      {
          socktmp= mainSocket.accept();
          rdr= new BufferedReader( new InputStreamReader(socktmp.getInputStream()));
          String t="";
          String name="";
          while((t=rdr.readLine())!=null){     &lt;&lt;&lt;&lt;&lt; **it stops here**
              name=t;
          }
          //rdr.close();
          LstClient.AddClient(name, socktmp);
  
          objwriter = new ObjectOutputStream(socktmp.getOutputStream());
          objwriter.writeObject(LstClient.clients);
          objwriter.flush();  
          objwriter.close();
     }
     catch(Exception ex){
          throw new Exception("Unable to Update Clients. Error :" + ex.getMessage());
     }
        finally{
          try{
              if(mainSocket!=null){
                  mainSocket.close();
              }
              if(socktmp!=null){
                  socktmp.close();
              }
              if(rdr!=null)
              {
                  rdr.close();
              }
              if(objwriter!=null)
              {
                  objwriter.close();
              }
  
          }
          catch(Exception ex1){
              throw new Exception("Unable to close streams after opeining. Error :"+ ex1.getMessage());
          }
  
  
     }
  
  
  }
  </code></pre>
  
  <p>and following is my client code:</p>
  
  <pre><code>public Client(String serverIp,int port,String name) throws Exception{
  
      try{
          if(mainSock!=null){
          mainSock.close();
          }
          mainSock= new Socket(serverIp, port);
          writer= new BufferedWriter(new OutputStreamWriter(mainSock.getOutputStream()));
  
          writer.write(name);
          writer.flush();
          **//writer.close();**
          Thread.sleep(1500);
          objin = new ObjectInputStream(mainSock.getInputStream());
          Hashtable&lt;String,Socket&gt; lst= new Hashtable&lt;String , Socket&gt;();
          lst = (Hashtable&lt;String, Socket&gt;) objin.readObject();
          cl = new LstClient();
          LstClient.clients = lst;
          System.out.println(LstClient.clients.size());
          objin.close();
  
      }
      catch(Exception ex){
          throw new Exception("Error : "+ ex.getMessage());
      }
      finally{
          if(mainSock!=null){
              mainSock.close();
  
          }
          if(writer!=null){
              writer.close();
          }
          if(objin!=null){
              objin.close();
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>I only get data in server or cursor goes on reading line on server side when i close writer in client end. but when i try to read after closing the writer at client end it says socket is closed so without closing it pauses on readline on server end
  please help</p>