 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Samson Fu Guest
|
Posted: Fri Jan 21, 2005 2:58 am Post subject: Indy10 TCPClient missing OnDisconnect Event. |
|
|
I have a simple test program as below (a TEdit with Text:= 'www.google.com', a TButton, a TMemo on a form) :
The problem is IdTCPClient1Disconnected never happen!
procedure TForm1.Button1Click(Sender: TObject);
Const
LF = #13;
CR = #10;
EOL = CR+LF;
Req =
'GET HTTP://%0:s/ HTTP/1.0'+EOL+
'Accept: */*'+EOL+
'User-Agent: Mozilla/4.0'+EOL+
'Host: %0:s'+EOL+
EOL;
begin
IdTCPClient1.Host:= Edit1.Text;
IdTCPClient1.Port:= 80;
IdTCPClient1.Connect;
IdTCPClient1.IOHandler.WriteLn(Format(Req, [Edit1.Text]));
While IdTCPClient1.Connected do
Begin
Memo1.Lines.Add(IdTCPClient1.IOHandler.ReadLn);
Application.ProcessMessages;
End;
end;
procedure TForm1.IdTCPClient1Disconnected(Sender: TObject);
begin
Memo1.Lines.Add('<EVENT> IdTCPClient1Disconnected');
end;
procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
Memo1.Lines.Add('<EVENT> IdTCPClient1Connected');
end;
--
Samson Fu
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Jan 21, 2005 11:17 am Post subject: Re: Indy10 TCPClient missing OnDisconnect Event. |
|
|
"Samson Fu" <fusamson (AT) gmail (DOT) com> wrote
| Quote: | The problem is IdTCPClient1Disconnected never happen!
|
Indy is not an event-driven asynchronous library to begin with. The
OnDisconnect event is only triggered when Disconnect() is explicitally
called. Your code is not doing that, so OnDisconnect is never triggered.
Likewise, OnConnect is triggered inside of Connect(). It is not an
asynchronous event at all.
Gambit
|
|
| Back to top |
|
 |
Samson Fu Guest
|
Posted: Sat Jan 22, 2005 1:07 am Post subject: Re: Indy10 TCPClient missing OnDisconnect Event. |
|
|
If it OnConnect and onDisconnect only happens when I call Connect and Disconnect, what's the propose of implement it?
By the way, how do you know a connection is terminated by server from the client side?
As I remember my example code above will DO raise OnDisconnect event in Indy9.
--
Samson Fu
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Samson Fu" <fusamson (AT) gmail (DOT) com> wrote in message
news:41f06ff2 (AT) newsgroups (DOT) borland.com...
The problem is IdTCPClient1Disconnected never happen!
Indy is not an event-driven asynchronous library to begin with. The
OnDisconnect event is only triggered when Disconnect() is explicitally
called. Your code is not doing that, so OnDisconnect is never triggered.
Likewise, OnConnect is triggered inside of Connect(). It is not an
asynchronous event at all.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Jan 22, 2005 10:11 am Post subject: Re: Indy10 TCPClient missing OnDisconnect Event. |
|
|
"Samson Fu" <fusamson (AT) gmail (DOT) com> wrote
| Quote: | how do you know a connection is terminated by server from the client side?
|
When you try to access the client socket, any reading/writing operations
will throw an exception
| Quote: | As I remember my example code above will DO raise OnDisconnect event in
Indy9. |
No, it does not.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|