🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.delphi.general
1 messages
1 total messages Started by niobi Tue, 07 Sep 2010 07:52
Delphi7 - Client/server InDy - Error during transmission of data
#151
Author: niobi
Date: Tue, 07 Sep 2010 07:52
88 lines
4286 bytes
Hello,
I'm a problem with InDy components, that I do not know well, becaus I
used Socket components (Delphi 5) and during migration to Delphi7 they
are vanished. I know that is possible to install package dclSocket,
but I prefer to migrate to this unfamiliar components, but is evident
that I've not understand nothing.

This is the source (an extract, that I think is sufficient).
The connection is on 127.0.0.1, the same computer, two distinct
procedures, the port > 50000.

procedure client
- - - - - - - - - - - - - - - - -
(components TIdTCPClient + TIdAntiFreeze)
Here, I create a file on disk, containing data to send to the server,
and send it dimension: Size := Length(File)
.  Client.WriteInteger(Size); // dimension packet
.  TmpStream := TMemoryStream.Create;
.  TmpStream.LoadFromFile(IndirProc+'\REPORT\TMS.DAT' ); // file
created on local disk
.  Client.OpenWriteBuffer;
.  try
.    Client.WriteStream(TmpStream);
.  except
.    on E: Exception do
.      MesServ('Transazione non eseguita: +#10+'"'+ E.Message+'"'+
.        #10+'Riprovare...');
.  end;
.  Client.CloseWriteBuffer;
.  FreeAndNil(TmpStream);


procedure Server
- - - - - - - - - - - - - - - - - - - -
(components TIdTCPServer + TIdThreadMgrDefault + TIdAntiFreeze.)
here, we are in event Server.OnExecute:

.  try
.    TmpStream := TFileStream.Create(IndirArch+'\Trans7',fmCreate);
.    AThread.Connection.ReadStream(TmpStream,-1,False);
.  except
.    on E: Exception do begin
.      MesServ(3,'Errore in lettura dati: '+E.Message); Ok := False;
.    end;
.  end;
.  FreeAndNil(TmpStream);

Problem !!!
- - - - - - - - -
In my intention, at the end of the operation, on the local disk (of
the server) now there is a file named "Trans7", but this is not.
The server is blocked at row "AThread.Connection.ReadStream...", and
the client remains waiting of an answer, and the two procedures remain
suspended.

Question:
The server reads on the buffer the data that I've sent with the
client,
and it writes the data on the TFileStream file, from position 0 to
position Size: is this just?

I've tested so:

.  try
.    TmpStream := TMemoryStream.Create;
.    AThread.Connection.ReadStream(TmpStream,-1,False);
.    TmpStream.SaveToFile(IndirArch+'\Trans7');
.  except
.    on E: Exception do begin
.      MesServ(3,'Errore in lettura dati: '+E.Message); Ok := False;
.    end;
.  end;
.  FreeAndNil(TmpStream);

In this case, the procedure server raise an error of Memory Overflow,
at line "AThread.Connection.ReadStream...", the flow continues in
"Except" and return to "try", in an infinite loop. The client remain
blocked on line "Client.WriteStream(TmpStream);", and I must close the
two procedures via TaskManager of the Windows.

I cannot to use ReadLn or WriteLn methods (but in this case, all
functions), because in my data there are numerous "#10" and "#13".

Where is the bug?
Thanks very much for answers and help, and I hope that my english is
at least comprensible.

Antonio
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads