title: Error 10054 api recv with Delphi SocketServer
body: <p>This question is about this message <code>"socket error: an existing connection was forcibly closed by the remote host (10054), on api 'recv'"</code></p>
  
  <p>We have a multitier application that we created using Delphi and uses Borland Socket Server on application server.</p>
  
  <p>This solution is installed on several clients of ours, but with just one of them this problem happens. Not on a regular basis.</p>
  
  <p>The application works well oiled almost the entire time, but once a while the client part hangs... </p>
  
  <p>Debugging the client part I found out that this message appears before it freezes.</p>
  
  <p>I installed WireShark to check the packets and this is what I found:</p>
  
  <ul>
  <li>The client sends a request to the server (PSH) </li>
  <li>The server does not send a acknowledge (ACK) </li>
  <li>The client sends a "TCP Retransmission" for 5 times</li>
  <li>Almost 20 seconds after the first packet the Wireshark shows an connection reset (RST)</li>
  </ul>
  
  <p>wireshark log:</p>
  
  <pre><code>205 16:38:02.763757000 192.168.3.63          10.250.1.5            TCP      95     50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  208 16:38:03.124843000 192.168.3.63          10.250.1.5            TCP      95     [TCP Retransmission] 50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  212 16:38:03.725205000 192.168.3.63          10.250.1.5            TCP      95     [TCP Retransmission] 50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  224 16:38:04.925619000 192.168.3.63          10.250.1.5            TCP      95     [TCP Retransmission] 50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  243 16:38:07.318803000 192.168.3.63          10.250.1.5            TCP      95     [TCP Retransmission] 50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  310 16:38:12.119776000 192.168.3.63          10.250.1.5            TCP      95     [TCP Retransmission] 50567 &gt; anet [PSH, ACK] Seq=1 Ack=1 Win=256 Len=41
  346 16:38:21.725165000 192.168.3.63          10.250.1.5            TCP      54     50567 &gt; anet [RST, ACK] Seq=42 Ack=1 Win=0 Len=0`
  </code></pre>
  
  <p>This happens on one machine at the time, while the remaining users work without any problem. That shows me that is not a problem with the SocketServer... Or is it?</p>
  
  <p>I also found these lines on ScktComp.pas:</p>
  
  <pre><code>procedure TCustomWinSocket.DoOpen;
  var
      timeout: Integer;
  begin
      timeout := 100;
      DoSetASyncStyles;
      Event(Self, seConnecting);
      // set the read(receive) timeout
      SetSockOpt(FSocket, SOL_SOCKET, SO_RCVTIMEO, @timeout, SizeOf(timeout));
      // set the send(write) timeout
      SetSockOpt(FSocket, SOL_SOCKET, SO_SNDTIMEO, @timeout, SizeOf(timeout));
      CheckSocketResult(WinSock.connect(FSocket, FAddr, SizeOf(FAddr)), 'connect');
      ...
  </code></pre>
  
  <p>Using ping to check the connection, I noticed some responses with more than 100ms or even 200ms. Can these timeouts (RCVTIMEO and SNDTIMEO) be the cause of all the problems?</p>
  
  <p>Any help?</p>
  
  <p>I am almost recoding the Delphi connection component trying to fix this, but I prefer not to.</p>
  
  <p>Thanks a lot,</p>
  
  <p>Z</p>