Recent

Author Topic: [SOLVED] Range check error with fprecv (Sockets)  (Read 2545 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
[SOLVED] Range check error with fprecv (Sockets)
« on: July 23, 2017, 05:11:57 pm »
hi All,
as per attached i am getting a range check error while writing the response to a request in a socket.
please advise on why the error would appear.
this is my first sockets unit, i am learning...

thank you

Code: Pascal  [Select][+][-]
  1. function TWeb.sWrite(AMsg: string): string;
  2. var
  3.   i: cardinal;
  4.   s: integer;
  5. begin
  6.   try
  7.     s := Length(AMsg);
  8.     if s < packet_size then
  9.       i := s
  10.     else
  11.       i := packet_size;
  12.  
  13.     writeln('start write');
  14.     while s > 0 do
  15.     begin
  16.       fpsend(_ASocket, PChar(AMsg), i, 0);
  17.       Delete(AMsg, 1, i);
  18.  
  19.       s := s - packet_size;
  20.       if s < packet_size then
  21.         i := s;
  22.     end;
  23.  
  24.     writeln('finish write');
  25.   except
  26.     on E: Exception do
  27.     begin
  28.       writeln('error write: ' + E.Message);
  29.       Result := E.Message;
  30.     end;
  31.   end;
  32. end;
  33.  
« Last Edit: July 23, 2017, 05:41:28 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: Range check error with fprecv (Sockets)
« Reply #1 on: July 23, 2017, 05:41:10 pm »
it looks like the below does not throw an exception:

Code: Pascal  [Select][+][-]
  1. function TWeb.sWrite(AMsg: string): string;
  2. begin
  3.   try
  4.     writeln('start write');
  5.     fpsend(_ASocket, PChar(AMsg), Length(AMsg), 0);
  6.     writeln('finish write');
  7.   except
  8.     on E: Exception do
  9.     begin
  10.       writeln('error write: ' + E.Message);
  11.       Result := E.Message;
  12.     end;
  13.   end;
  14. end;
Lazarus 2.0.2 64b on Debian LXDE 10

 

TinyPortal © 2005-2018