Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Apr : Re: connection closed gracefully form close problem

www.cryer.info
Managed Newsgroup Archive

Re: connection closed gracefully form close problem

Subject:Re: connection closed gracefully form close problem
Posted by:"mustafa korkmaz" (no..@none.com)
Date:4 Apr 2007 00:21:35

I think 9.0.50 version is not on internet.
Or somebody hides it in very deep place..
I couldnt find...

"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"mustafa korkmaz" <mustafakorkmaz@gmail.com> wrote in message
>news:4612ad94$1@newsgroups.borland.com...
>
>> But when the server close client connection than if I try to
>> close client application this exception message appears:
>> raise exception class Ewin32Error with message 'Win32 Error.
>> code:1400. Invalid window handle'
>
>That is not an Indy-related error message.
>
>I see that you are using the FreeOnTerminate property in your thread.
>You should not be using that, especially if you are using the
>TThread.WaitFor() method as well (which you should be in this case).
>
>>   while ( not Terminated ) and ( frmOkeyMainform.exitplease =
>false ) do
>
>Get rid of that exitplease flag.  It has no business being in your
>thread.  The Terminated property is enough.
>
>>       if not frmOkeyMainform.TcpClient.Connected then Terminate
>
>Get rid of that as well.  You don't need to check the Connected()
>method.  If you try to read from a disconnected socket, an exception
>will be raised that you can catch.
>
>>         Synchronize( UseFormcomponents );
>
>Why are you synchronizing the rest of your reading?  You should not be
>doing that.  Do all of the reading in the context of the worker
>thread.  Synchronize just the VCL/UI access and nothing else.
>
>For example:
>
>    TClientThread = class(TThread)
>    protected
>        procedure Execute; override;
>        //...
>    end;
>
>    procedure TClientThread.Execute;
>    var
>        firtbyte: byte;
>        c: char;
>    begin
>        while not Terminated do
>        begin
>            try
>                frmOkeyMainform.TcpClient.ReadBuffer(firstbyte,
>SizeOf(firstbyte));
>                if firstbyte = 45 then
>                begin
>                    frmOkeyMainform.TcpClient.ReadBuffer(c,
>sizeof(char));
>                    Synchronize(UseFormComponents);
>                end
>                else if firstbyte = 46 then
>                    // ...
>                end;
>            except
>                Terminate;
>            end;
>        end;
>    end;
>
>> procedure TfrmOkeyMainform.FormClose(Sender: TObject;
>>   var Action: TCloseAction);
>> begin
>>   exitplease := true;
>>   try
>>    if TcpClient.connected then TcpClient.Disconnect;
>>   except
>>   end;
>> ........
>> end;
>
>You should be terminating the thread, ie:
>
>    var
>        ClientThread: TClientThread = nil;
>
>    procedure TfrmOkeyMainform.Myconnect;
>    begin
>        TcpClient.Connect(20000);
>        try
>            ClientThread := TClientThread.Create(False);
>        except
>            TcpClient.Disconnect;
>            raise;
>        end;
>     end;
>
>    procedure TfrmOkeyMainform.FormClose(Sender: TObject; var Action:
>TCloseAction);
>    begin
>        if ClientThread <> nil then ClientThread.Terminate;
>        try
>            TCPClient.Disconnect;
>        finally
>            ClientThread <> nil then
>            begin
>                ClientThread.WaitFor;
>                FreeAndNil(ClientThread);
>            end;
>        end;
>    end;
>
>> Indy version is 9.0.18
>
>That is a very old version of Indy 9.  The current development
>snapshot is 9.0.50.  You should consider upgrading to ensure you have
>all of the latest bug fixes and features.
>
>
>Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive