Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Delphi - Error (loop?) Server during read data from socket
Forum - Delphi - Error (loop?) Server during read data from socket

Avatar
niobi (Normal User)
Newbie


Messaggi: 13
Iscritto: 23/08/2010

Segnala al moderatore
Postato alle 10:44
Mercoledė, 22/09/2010
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

PM Quote
Avatar
HeDo (Founder Member)
Guru^2


Messaggi: 2765
Iscritto: 21/09/2007

Segnala al moderatore
Postato alle 12:02
Mercoledė, 22/09/2010

sorry niobi, this is an italian forum, you can't post here in english :)

PM Quote
Avatar
niobi (Normal User)
Newbie


Messaggi: 13
Iscritto: 23/08/2010

Segnala al moderatore
Postato alle 18:08
Giovedė, 23/09/2010
ok, ok,
sono cosė abituato a forums in lingua ingkese... ma avrei dovuto capirlo.
Scusate.
Potreste, per favore, rimuovore il mio post in inglese? Provvedo a riscriverlo in italiano.
Grazie ancora.
Antonio

PM Quote