Delphi7 - Error (loop?) Server during read data from socket

Please discuss general Delphi programming topics here.

Delphi7 - Error (loop?) Server during read data from socket

Postby niobi » September 22nd, 2010, 9:09 am

I've two procedures (client and server). Object components are InDy9 TIdTCP. SO is XP-HOME.
Operations of the che client:
// connection
. try
... CliSok.Connect();
... CliSok.ReadTimeout := 1000;
... CliSok.Socket.UseNagle := False;
. except
... on E: ESocketError do
..... MesServ(4,'Connessione al server: +#10+'"'+E.Message+'"'+#10+'Riprovare...');
. end;
// sending
. try
... try
..... CliSok.WriteInteger(CarSped); // value of dimension data stored in CarSped
..... TmpStream := TMemoryStream.Create;
..... TmpStream.LoadFromFile(IndirProc+'\REPORT\TMS.DAT');
..... CliSok.OpenWriteBuffer;
..... CliSok.WriteStream(TmpStream);
... except
..... on E: ESocketError do
....... MesServ(4,'Transazione non eseguita: ' +#10+'"'+E.Message+'"'+#10+'Riprovare...');
... end;
. finally
... CliSok.CloseWriteBuffer;
... FreeAndNil(TmpStream);
. end;
. CliSok.Disconnect; // chiude connessione al server
Operations of the server:
// inizialize the Server.Binding, then turn Server.Active to True
. procedure SerSokExecute(AThread: TIdPeerThread);
. var Size: integer; Proce,Codice: string; TmpStream: TFileStream;
. begin
. if AThread.Terminated or (not AThread.Connection.Connected) then Exit;
. try
... Size := AThread.Connection.ReadInteger;
... if Size = 0 then Exit; // spedizione errata?
... TmpStream := TFileStream.Create(IndirArch+'\Trans1.txt',fmCreate);
... AThread.Connection.ReadStream(TmpStream,Size,False);
... if not FileExists(IndirArch+'\Trans1.txt') then
... MesServ(3,'Errore di scrittura della transazione su disco...'+#10+... 'provenienza: '+AThread.Connection.Socket.LocalName);
. except
... on E: Exception do
... MesServ(3,'Errore in lettura dati: '+E.Message); Ok := False;
. end;
. FreeAndNil(TmpStream);
. end;
- - -
The problem is in th OnExecute method: the server read the buffer,
and create a file by TFileStream: all ok;
but the flow of the procedure, after the "FreeAndNil()" row, come back to the row
"if AThread.Terminated...", read the Size value from AThread object and terminates
in error, jumping to the except module.
The value "AThread.Terminated" return "True", but the client, after the sending,
has closed the connection: why this? why the method Execute is re-actived after the read
of the buffer? Instead to close the peer connection (with "Disconnect"), the client must close
the socket connection (with "DisconnectSocket")?
I am going crazy for this problem and I don't know how to go out.
Please, give me a tip.
Thanks for help.
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 1 guest

cron