Delphi7 - Client/server InDy - Error during transmission of

Please discuss general Delphi programming topics here.

Delphi7 - Client/server InDy - Error during transmission of

Postby niobi » September 8th, 2010, 6:00 pm

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
niobi
Member
Member
 
Posts: 4
Joined: September 8th, 2010, 5:55 pm

Re: Delphi7 - Client/server InDy - Error during transmission

Postby Kambiz » September 18th, 2010, 3:56 pm

Socket components are still available on Delphi 7 and higher, but not at design time.
To use your old code, create the socket component at OnCreate event of your form and pass Self as the Owner parameter. No need to free the socket component.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Delphi7 - Client/server InDy - Error during transmission

Postby niobi » September 20th, 2010, 8:08 am

Ok, thanks for tip.
But:
the InDy components are better then the old Socket components, or not?
Because during the use of the socket components, it happens that the server resulted disconnected, while it was connected to the socket... and the user was forced to re-start the client procedure and the server procedure...
Now, I am implementing my numerous procedures with the InDy components, and I hope this is better.-

Antonio
niobi
Member
Member
 
Posts: 4
Joined: September 8th, 2010, 5:55 pm

Re: Delphi7 - Client/server InDy - Error during transmission

Postby niobi » September 20th, 2010, 8:17 am

ah,
I'm solved the problem of the transmission like this:
(1) timeout
AThread.Connection.ReadTimeout := 1000; // 1 second timeout
(2) set usenagle=false
AThread.Connection.Socket.UseNagle := False;
and so, the transmission have success.
But there are others problems, that i'm solving...
Antonio
niobi
Member
Member
 
Posts: 4
Joined: September 8th, 2010, 5:55 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 7 guests

cron