title: Client Exception: Software caused connection abort: recv failed
body: <p>I've been playing around with my Java client app. Behaviour is very similar to this post (and others):</p>
  
  <p><a href="https://stackoverflow.com/questions/135919/java-net-socketexception-software-caused-connection-abort-recv-failed">java.net.SocketException: Software caused connection abort: recv failed</a></p>
  
  <p>As yet I've not found the answer - hence this post. I have a idea what is wrong but I'm not sure what to do about it.</p>
  
  <p>The protocol is simple - read some data in, send back an ACK and repeat (until terminted). </p>
  
  <p>I've been looking at what is going on with WireShark, and is seems the TCP window is filling up. I'm performing a flush() on the DataOutputStream (For the ACKs) but doesn't change the fact at after a while I get this exception (I can see on WireShark that there is always a window problem right before the Java exception).</p>
  
  <p>So how to I make sure in Java that my TCP windows/buffers are clear (Which I think is the root cause of the problem?) seems to be no flush on the DataInputStream. Make be wonder that whilst I might be reading it the TCP stack is filling up.</p>
  
  <p>Many Thanks</p>
  
  <p>Mark</p>
  
  <p>I've attached the basic code calls below:</p>
  
  <pre><code>     public void connectToServer()
   {
       //Create socket connection      
       try
       {
           if (lSocket == null)
           {
               lSocket = new Socket("localhost", 7651);
               lSocket.setSoTimeout(0);
               lInDataStream = new DataInputStream(lSocket.getInputStream());
               lOutDataStream = new DataOutputStream(lSocket.getOutputStream());
           }
       }
       catch (UnknownHostException e)
       {
           System.out.println("Unknown host: localhost");
       }
       catch  (IOException e)
       {
           System.out.println("No I/O");
       }       
   }
  
   public void readSocket() throws IOException
   {
       //Receive data from ROS SerialtoNetwork server
       if (lSocket != null)
       {
          lInDataStream.readInt();    
          lInDataStream.readFully(cbuf);
  
          lOutDataStream.writeBytes("Ack");
          lOutDataStream.flush();
  
          //String lstr = new String(cbuf);
          //System.out.print(lstr);
          //System.out.println(""); 
      }
   }
  
   public String getDataBuffer()
   {
       String lstr = new String(cbuf);
       return lstr;
   }
  </code></pre>