Board index » delphi » (Indy 8.0.22) Terminate Thread Timeout Error

(Indy 8.0.22) Terminate Thread Timeout Error

Hi All
I am trying to write a registration program using TCP Client/Server
In my client my user fills out registration details

RegWiz.OnRegister(Sender:TObject);
Var TCPMessage:TStrings;
.....
TCPMessage.Add('FieldName|Value');
TCPClient.Write(TCPMessage.Text);
.....
 (interpret response)
end;

in the server onexecute event of idTCPServer

 LogMemo.Lines.Add(AThread.Connection.ReadLn);

This shows all the sent lines but the problem arises when I want to
deactivate the server
I am new to indy so I am not too sure how to go about even using these
components yet
Should I use some command to force closure of the client connection?
Is there something received by the client to tell it to terminate the
connection or to inform it that the connection is being terminated?
This error does not happen if I close the client first

Any help will be greatly appreciated

--
Regards
Peter I. Dunne

http://www.gda.bizhosting.com (A developers site by developers for
developers)
No attachments in replies unless requested please

 

Re:(Indy 8.0.22) Terminate Thread Timeout Error


"Peter Dunne" <refugeeag...@hotmail.com> schrieb im Newsbeitrag
news:3c443eea_2@dnews...

Quote
> Hi All
> I am trying to write a registration program using TCP Client/Server
> In my client my user fills out registration details

> RegWiz.OnRegister(Sender:TObject);
> Var TCPMessage:TStrings;
> ....
> TCPMessage.Add('FieldName|Value');
> TCPClient.Write(TCPMessage.Text);
> ....
>  (interpret response)
> end;

> in the server onexecute event of idTCPServer

>  LogMemo.Lines.Add(AThread.Connection.ReadLn);

Go to the hell! You must handle visual VCL from within a thread.

- Show quoted text -

Quote

> This shows all the sent lines but the problem arises when I want to
> deactivate the server
> I am new to indy so I am not too sure how to go about even using these
> components yet
> Should I use some command to force closure of the client connection?
> Is there something received by the client to tell it to terminate the
> connection or to inform it that the connection is being terminated?
> This error does not happen if I close the client first

> Any help will be greatly appreciated

> --
> Regards
> Peter I. Dunne

> http://www.gda.bizhosting.com (A developers site by developers for
> developers)
> No attachments in replies unless requested please

Re:(Indy 8.0.22) Terminate Thread Timeout Error


Quote
Ernst Gerlach wrote in message <3c448e4b_1@dnews>...
>Go to the hell! You must handle visual VCL from within a thread.

Not too good on the english language and very rude
Have been to hell, got the shirt! Left!
Next time try pointing out errors politely, you will find people respond
better
How about a tip on the correct way?
Then I can be as perfect as you!
Also try reading the guidelines for newsgroups!

My question remains as before however it now seems I must read more about
threads!

I am trying to write a registration program using TCP Client/Server
In my client my user fills out registration details

RegWiz.OnRegister(Sender:TObject);
Var TCPMessage:TStrings;
.....
TCPMessage.Add('FieldName|Value');
TCPClient.Write(TCPMessage.Text);
.....
(interpret response)
end;

in the server onexecute event of idTCPServer

LogMemo.Lines.Add(AThread.Connection.ReadLn);

This shows all the sent lines but the problem arises when I want to
deactivate the server
I am new to indy so I am not too sure how to go about even using these
components yet
Should I use some command to force closure of the client connection?
Is there something received by the client to tell it to terminate the
connection or to inform it that the connection is being terminated?
This error does not happen if I close the client first

Any help will be greatly appreciated

Re:(Indy 8.0.22) Terminate Thread Timeout Error


Quote
Peter Dunne <refugeeag...@hotmail.com> wrote in message

news:3c449f13$1_1@dnews...

Quote
> Ernst Gerlach wrote in message <3c448e4b_1@dnews>...
> >Go to the hell! You must handle visual VCL from within a thread.

> Not too good on the english language and very rude
> Have been to hell, got the shirt! Left!
> Next time try pointing out errors politely, you will find people respond
> better
> How about a tip on the correct way?
> Then I can be as perfect as you!
> Also try reading the guidelines for newsgroups!

I think Ernst is winding you up for some reason!  Ernst has posted many
helpful hints to this group in the past and is, I think, unlikely to have
meant what the said to be taken badly.  If he did mean it badly, I can only
assume that you are a Man U. or West Ham supporter & as such are fair game.

It is a bit, (!), dodgy to load up a Tmemo direct from a thread.  It may
work today but....

You could load the incoming data into a TstringList, created in the thread,
and post it to the main VCL thread.  There, you could add it to the Tmemo &
free it.

As for your original question, what sort of error do you get?  If you free
the server object, the server should perform a managed disconnect of all the
clients - it should all work OK....

Rgds,
Martin

Re:(Indy 8.0.22) Terminate Thread Timeout Error


Hi
Ok I will give Ernst the benefit of the doubt, as we all know these things
are open to mis-interpretation anyhow

Back to the original question, I am getting time out errors terminating the
thread, however I have since found that if the client is closed first then
the error does not happen so I think a change in my program will solve this

On the second point, Threads, I simply copied one of the indy samples and
did not know for sure if the thread was already synchronized by the indy
component, I see now that it is not
After a few tests, some reading of the indy source and on threads I realized
the best way to handle my connection is by defining a new TThreadClass and
using it with TidTCPServer, so I think I should be ok now
If you got any tips on forcing a disconnect from the server and detecting it
in the client I would be grateful

Man-U who??,
Westham, Where??
Middlesbrough, Nice stadium, not sure about the team!, I was there putting
in turnstiles when they built the place!, does this make me fair game?

--
Regards
Peter I. Dunne

http://www.gda.bizhosting.com (A developers site by developers for
developers)
No attachments in replies unless requested please

Quote
Martin James wrote in message <3c451760_1@dnews>...

>Peter Dunne <refugeeag...@hotmail.com> wrote in message
>news:3c449f13$1_1@dnews...
>> Ernst Gerlach wrote in message <3c448e4b_1@dnews>...
>> >Go to the hell! You must handle visual VCL from within a thread.

>> Not too good on the english language and very rude
>> Have been to hell, got the shirt! Left!
>> Next time try pointing out errors politely, you will find people respond
>> better
>> How about a tip on the correct way?
>> Then I can be as perfect as you!
>> Also try reading the guidelines for newsgroups!

>I think Ernst is winding you up for some reason!  Ernst has posted many
>helpful hints to this group in the past and is, I think, unlikely to have
>meant what the said to be taken badly.  If he did mean it badly, I can only
>assume that you are a Man U. or West Ham supporter & as such are fair game.

>It is a bit, (!), dodgy to load up a Tmemo direct from a thread.  It may
>work today but....

>You could load the incoming data into a TstringList, created in the thread,
>and post it to the main VCL thread.  There, you could add it to the Tmemo &
>free it.

>As for your original question, what sort of error do you get?  If you free
>the server object, the server should perform a managed disconnect of all
the
>clients - it should all work OK....

>Rgds,
>Martin

Re:(Indy 8.0.22) Terminate Thread Timeout Error


"Peter Dunne" <refugeeag...@hotmail.com> schrieb im Newsbeitrag
news:3c456b6c$1_2@dnews...
Quote
> Hi
> Ok I will give Ernst the benefit of the doubt, as we all know these things
> are open to mis-interpretation anyhow

> Back to the original question, I am getting time out errors terminating
the
> thread, however I have since found that if the client is closed first then
> the error does not happen so I think a change in my program will solve
this

There can be two reasons for this behavior, a) in case of the missing
syncronize
the thread can jump out of control,
b) if you design a own protocol, it necessary to implement a QUIT command
and a NOOP commant and a read timeout control. (witch is more easy if you
can
update to 9.x)
Quote
> On the second point, Threads, I simply copied one of the indy samples and
> did not know for sure if the thread was already synchronized by the indy
> component, I see now that it is not
> After a few tests, some reading of the indy source and on threads I
realized
> the best way to handle my connection is by defining a new TThreadClass and
> using it with TidTCPServer, so I think I should be ok now
> If you got any tips on forcing a disconnect from the server and detecting
it
> in the client I would be grateful

Yoe do not need a new threadclass, you can copy your information to a global
stringvar and syncronize the display procedure. you have to pack the whole
action
into a tcriticalsection.
another technic is to use postmessage and sendmessage to the handle of your
mainform.

hth Ernst

Quote

> Man-U who??,
> Westham, Where??
> Middlesbrough, Nice stadium, not sure about the team!, I was there putting
> in turnstiles when they built the place!, does this make me fair game?

> --
> Regards
> Peter I. Dunne

> http://www.gda.bizhosting.com (A developers site by developers for
> developers)
> No attachments in replies unless requested please

> Martin James wrote in message <3c451760_1@dnews>...

> >Peter Dunne <refugeeag...@hotmail.com> wrote in message
> >news:3c449f13$1_1@dnews...
> >> Ernst Gerlach wrote in message <3c448e4b_1@dnews>...
> >> >Go to the hell! You must handle visual VCL from within a thread.

> >> Not too good on the english language and very rude
> >> Have been to hell, got the shirt! Left!
> >> Next time try pointing out errors politely, you will find people
respond
> >> better
> >> How about a tip on the correct way?
> >> Then I can be as perfect as you!
> >> Also try reading the guidelines for newsgroups!

> >I think Ernst is winding you up for some reason!  Ernst has posted many
> >helpful hints to this group in the past and is, I think, unlikely to have
> >meant what the said to be taken badly.  If he did mean it badly, I can
only
> >assume that you are a Man U. or West Ham supporter & as such are fair
game.

> >It is a bit, (!), dodgy to load up a Tmemo direct from a thread.  It may
> >work today but....

> >You could load the incoming data into a TstringList, created in the
thread,
> >and post it to the main VCL thread.  There, you could add it to the Tmemo
&
> >free it.

> >As for your original question, what sort of error do you get?  If you
free
> >the server object, the server should perform a managed disconnect of all
> the
> >clients - it should all work OK....

> >Rgds,
> >Martin

Re:(Indy 8.0.22) Terminate Thread Timeout Error


thanks for the info, much appreciated
I think I will have to create my own thread class because it is possible I
would have a number of clients accessing the server at the same time which
would corrupt the global data
The postmessage & send message will however solve my vcl update problem
The issue of threads was one which had me concerned as I did not know how
the indy components handled this, however the info gained here and reading
the source & help for indy have answered my questions so hopefully I can get
the job done now

--
Regards
Peter I. Dunne

http://www.gda.bizhosting.com (A developers site by developers for
developers)
No attachments in replies unless requested please

Quote
Ernst Gerlach wrote in message <3c46d85a_2@dnews>...
>"Peter Dunne" <refugeeag...@hotmail.com> schrieb im Newsbeitrag
>news:3c456b6c$1_2@dnews...
>> Hi
>> Ok I will give Ernst the benefit of the doubt, as we all know these
things
>> are open to mis-interpretation anyhow

>> Back to the original question, I am getting time out errors terminating
>the
>> thread, however I have since found that if the client is closed first
then
>> the error does not happen so I think a change in my program will solve
>this

>There can be two reasons for this behavior, a) in case of the missing
>syncronize
>the thread can jump out of control,
>b) if you design a own protocol, it necessary to implement a QUIT command
>and a NOOP commant and a read timeout control. (witch is more easy if you
>can
>update to 9.x)
>> On the second point, Threads, I simply copied one of the indy samples and
>> did not know for sure if the thread was already synchronized by the indy
>> component, I see now that it is not
>> After a few tests, some reading of the indy source and on threads I
>realized
>> the best way to handle my connection is by defining a new TThreadClass
and
>> using it with TidTCPServer, so I think I should be ok now
>> If you got any tips on forcing a disconnect from the server and detecting
>it
>> in the client I would be grateful
>Yoe do not need a new threadclass, you can copy your information to a
global
>stringvar and syncronize the display procedure. you have to pack the whole
>action
>into a tcriticalsection.
>another technic is to use postmessage and sendmessage to the handle of your
>mainform.

>hth Ernst

Re:(Indy 8.0.22) Terminate Thread Timeout Error


"Peter Dunne" <refugeeag...@hotmail.com> schrieb im Newsbeitrag
news:3c4728b5$1_2@dnews...
Quote
> thanks for the info, much appreciated
> I think I will have to create my own thread class because it is possible I
> would have a number of clients accessing the server at the same time which
> would corrupt the global data
> The postmessage & send message will however solve my vcl update problem
> The issue of threads was one which had me concerned as I did not know how
> the indy components handled this, however the info gained here and reading
> the source & help for indy have answered my questions so hopefully I can
get
> the job done now

> --
> Regards
> Peter I. Dunne

Why neew class?
Indy server thread has a pointer "thread.Data".
You define a TObject for your needs like

MyObject = TObject
  UserName: string;
  anyNumber: integer;
  <and  others>
end;

then in OnConnect like:

procedure TFm_Server.Pop3ServerConnect(AThread: TIdPeerThread);
var
  PData : TPop3Data;
begin
  PData := TPop3Data.Create;
  <here you can fill the object with the first informationes like ip)
  AThread.Data := PData;
end;

in OnDisconnect you must free it like:

procedure TFm_Server.Pop3ServerDisconnect(AThread: TIdPeerThread);
var
  PData : TPop3Data;
begin
  PData := Pointer(AThread.Data); // you have to assign
  PData.Free;
  AThread.Data := nil;
end;

in OnExecute (or every CommandHandler, if you use this), you have to
do a new assign like:

procedure TFm_Server.Pop3ServerExecute(AThread: TIdPeerThread);
var
  PData : TPop3Data;
begin
  PData := Pointer(AThread.Data);
  // do your other stuff, you can now work
  // with your object like PData.UserName := ReceivedString;
  // this is a threadsave manner
  <do your other stuff>
end;

Why a new class? Indy has buit in all you need
hth
Ernst

Re:(Indy 8.0.22) Terminate Thread Timeout Error


Again you help save my hair, now I don't need to pull it out.
I lack your experience with Indy and am still trying to work out how things
work
I was looking at creating a new thread class to contain the data but your
solution is much better
The more of Indy I see the more I like it!
Thanks again for your help!

--
Regards
Peter I. Dunne

http://www.gda.bizhosting.com (A developers site by developers for
developers)
No attachments in replies unless requested please

Quote
Ernst Gerlach wrote in message <3c481765_2@dnews>...
>Why neew class?
>Indy server thread has a pointer "thread.Data".
>You define a TObject for your needs like

>MyObject = TObject
>  UserName: string;
>  anyNumber: integer;
>  <and  others>
>end;

>then in OnConnect like:

>procedure TFm_Server.Pop3ServerConnect(AThread: TIdPeerThread);
>var
>  PData : TPop3Data;
>begin
>  PData := TPop3Data.Create;
>  <here you can fill the object with the first informationes like ip)
>  AThread.Data := PData;
>end;

>in OnDisconnect you must free it like:

>procedure TFm_Server.Pop3ServerDisconnect(AThread: TIdPeerThread);
>var
>  PData : TPop3Data;
>begin
>  PData := Pointer(AThread.Data); // you have to assign
>  PData.Free;
>  AThread.Data := nil;
>end;

>in OnExecute (or every CommandHandler, if you use this), you have to
>do a new assign like:

>procedure TFm_Server.Pop3ServerExecute(AThread: TIdPeerThread);
>var
>  PData : TPop3Data;
>begin
>  PData := Pointer(AThread.Data);
>  // do your other stuff, you can now work
>  // with your object like PData.UserName := ReceivedString;
>  // this is a threadsave manner
>  <do your other stuff>
>end;

>Why a new class? Indy has buit in all you need
>hth
>Ernst

Other Threads