Recent

Author Topic: access violation while using Lnet TCP Server Console  (Read 1070 times)

opendelphi

  • New Member
  • *
  • Posts: 17
access violation while using Lnet TCP Server Console
« on: April 18, 2019, 01:43:24 pm »
Hi guys , i am trying to extend the lnet tcp server console sample by allowing receiving files from tcp server .
the error msg while try to download the file from server
Code: Pascal  [Select][+][-]
  1. An unhandled exception occurred at $0000000000428D7F:
  2.                                                      EAccessViolation: Access violation
  3.          $0000000000428D7F
  4.                             $000000000047840F line 1086 of ../lib/lnet.pp
  5.                                                                            $0000000000400EC5 line 167 of lserver.pp
  6.  
  7.  
so this is server side code on receive
Code: Pascal  [Select][+][-]
  1.  
  2.   if aSocket.GetMessage(FServerReceivedStr) > 0 then begin
  3.     if FServerReceivedStr <> 'file' then
  4.  
  5.     writeln(FServerReceivedStr)
  6.      else
  7.         begin
  8.           FIStream.LoadFromFile('/root/Desktop/enumeration/server/file.txt');
  9.           n := FIStream.Size;
  10.           SetLength(FBuffer, FIStream.Size);
  11.           n := Length(FBuffer);
  12.           FIStream.Position := 0;
  13.           FIStream.Read(FBuffer[0], FIStream.Size);
  14.           n := Length(FBuffer);
  15.           FPos := 0;
  16.     // send image
  17.           OnCa(aSocket);
  18.         end;
  19.      // if send fails write error
  20.    // end;
  21.  end;
  22. end;                          
  23.  

on Can Send :

Code: Pascal  [Select][+][-]
  1.  
  2. if FServerReceivedStr = 'file' then
  3.   begin
  4.   { repeat the sending until we sent the whole buffer, or .Send return 0 -- means we filled the send buffer for now. NOTE: FSendIndex  has to begin at 1 for a string! }
  5.     repeat
  6.     { try to send the rest of the buffer we didn't send yet }
  7.       n := Length(FBuffer) - FPos;
  8.       if n > 0 then
  9.         n := FCon.Send(FBuffer[FPos], n);
  10.     { if we sent something, move us in the buffer so we don't re-send the same part }
  11.       Inc(FPos, n);
  12.     until (n = 0) or (FPos > Length(FBuffer));
  13.   end
  14.   else
  15.     FCon.SendMessage(FServerReceivedStr, aSocket);
  16.                                                          
  17.  


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: access violation while using Lnet TCP Server Console
« Reply #1 on: April 18, 2019, 04:14:31 pm »
I have a limited knowledge of lnet but there doesn't seem to be anything very wrong in those snippets, other than the total lack of exception handling in both, and the multiple times you set n (without using it for anything) to the same value in one form or another in the first.

Can you share a compilable demo or more detailed code (p.e. to see where and how you're creating the streams, what OnCa() does etc.)? And what's there in the lines pointed to by the exception message?
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

opendelphi

  • New Member
  • *
  • Posts: 17
Re: access violation while using Lnet TCP Server Console
« Reply #2 on: April 18, 2019, 05:20:06 pm »
i have fixed that error but still not able to get the file from server into client , below is example of code .

 

TinyPortal © 2005-2018