Recent

Author Topic: Synapse: Reading data timeout  (Read 574 times)

bpranoto

  • Full Member
  • ***
  • Posts: 183
Synapse: Reading data timeout
« on: June 30, 2024, 02:17:26 pm »
Using synapse version 40.1 this code snippet fails to receive the string
Code: Pascal  [Select][+][-]
  1. var
  2.   FConn:TTCPBlockSocket
  3.  
  4. ....
  5.       if FConn.CanRead(3000) then begin
  6.         FileVersion:=FConn.RecvString(12000);
  7.       end;
  8.  
  9.  

However, if I change the code to:
Code: Pascal  [Select][+][-]
  1.       FileVersion:='';
  2.       Start:=GetTickCount64;
  3.  
  4.       while FileVersion='' do begin
  5.         if FConn.CanRead(0) then begin
  6.           FileVersion:=FConn.RecvString(12000);
  7.         end;
  8.         if (GetTickCount64 - Start)>1000 then begin
  9.           // timeout
  10.           break;
  11.         end;
  12.       end;
  13.       if FileVersion <>'' then begin
  14.           ...
  15.       end;
  16.       .......
  17.  
It successfully receives the string

I think in the first verson, FConn.CanRead(3000) will wait for 3000 miliseconds to check if the string arrive, while in the secod version it only wait for 1000 ms to check. My question is why the first version fails even though it waits longer?
« Last Edit: June 30, 2024, 02:31:41 pm by bpranoto »

bpranoto

  • Full Member
  • ***
  • Posts: 183
Re: Synapse: Reading data timeout
« Reply #1 on: July 01, 2024, 08:34:05 am »
It turns it is my fault.

On the server side, I use Indy and when I send message to the client, I add CRLF to the the message string like this:

Server
Code: Pascal  [Select][+][-]
  1. // Indy
  2. Self.FContext.Connection.IOHandler.WriteLn(FileVersion+#13#10);
  3.  

The synapse client, reading the file version string message
Code: Pascal  [Select][+][-]
  1.       if FConn.CanRead(3000) then begin
  2.         FileVersion:=FConn.RecvString(12000);
  3.       end;
  4.  
it only fetch string, and the CRLF is still left in the buffer. when it retrieve the next message, it gets a CRLF which is an empty string.



 

TinyPortal © 2005-2018