Recent

Author Topic: Ararat Synapse RecvString() question  (Read 630 times)

rainer

  • Newbie
  • Posts: 2
Ararat Synapse RecvString() question
« on: March 05, 2024, 09:16:27 am »
Hello. 
I am not sure where ask this question, so I try here.

I am working on a little daemon (server), written in FreePascal on|for Linux.   It will communicate with IoT clients through TCP/IP. 
My problem is this extremely unreliable NB-IoT.  Sometimes Round-Trip-Times of 3-5 seconds, sometimes connection loss, ... 

I wrote a function to transmit a data packet. It sends a string, then it awaits the confirmation (a string with 'ACK'+<CRLF>). I configured a very long timeout of 15s for receiving a response (because of this sometimes long delays).

Code: Pascal  [Select][+][-]
  1. // Send data
  2.   function SendDataBlock(DataBlock: string): boolean;
  3.   var  s: string;
  4.   begin
  5.     ASocket.SendString(DataBlock+CRLF);   // Send Data
  6.     s:=ASocket.RecvString(timeout_rcv);   // Await respoonse
  7.     SendDataBlock:=pos('Ok',s)>0;    
  8.   end;
  9.  

This function works fine, as long something is received.  But it rises an Exception when Synapse reaches the timeout (line 6).

Is there a simple way to make RecvString return an empty string on timeout, or to detect and trigger on timeout?


I spent lots of time on finding any useful documentation, code examples, etc., but I had no success.    Is there any "code collection" available as downloadable PDF, showing how to use Synapse?  Need to say, I do not use Lazarus.  I use only FreePascal.  If somebody wants to see the complete code for better understanding, this is possible on request.
« Last Edit: March 05, 2024, 09:18:34 am by rainer »

paweld

  • Hero Member
  • *****
  • Posts: 1278
Re: Ararat Synapse RecvString() question
« Reply #1 on: March 05, 2024, 11:08:02 am »
You can disable exception throwing by synapse. Add the following code after creating TBlockSocket:
Code: Pascal  [Select][+][-]
  1. ASocket.RaiseExcept := False;
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018