 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Squeller27 Guest
|
Posted: Mon Nov 17, 2003 8:06 pm Post subject: TidTCPServer: thread sometimes killed |
|
|
Hi,
My TidTCPServer component handles request from different clients.
Unfortunately, sometimes the thread that handles the requests from those
clients suddenly gets killed somehow. I've noticed this after taking a look
at the taskmanager: normally the application has 2 threads (main thread of
the form and the thread of the TIdTCPServer component), but after the
failure there is only 1 thread. From that moment it is impossible for a
client to establish a new connection. I have to restart the server program
to establish a new connection.
I wonder if anyone has experienced this before. If so, what the solution for
this problem?
OBTW, I'm using Delphi 6, Indy 8 and Windows 2000.
Thanks in advance,
Eric
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Nov 17, 2003 8:17 pm Post subject: Re: TidTCPServer: thread sometimes killed |
|
|
"Squeller27" <squeller_5 (AT) hotmail (DOT) com> wrote
| Quote: | My TidTCPServer component handles request from different clients.
Unfortunately, sometimes the thread that handles the requests from
those clients suddenly gets killed somehow. I've noticed this after
taking a look at the taskmanager: normally the application has 2
threads (main thread of the form and the thread of the TIdTCPServer
component), but after the failure there is only 1 thread. From that
moment it is impossible for a client to establish a new connection.
|
What you describe suggests that the listener thread that accepts new
connections is terminating. But if you are servicing client data packets,
those are handled on a completely different thread then the listening
thread. The only way Ican see the listening thread terminating prematurely
is if the server socket fails to accept a new connection.
Gambit
|
|
| Back to top |
|
 |
Squeller27 Guest
|
Posted: Mon Nov 17, 2003 10:10 pm Post subject: Re: TidTCPServer: thread sometimes killed |
|
|
Thanks for your reply. Of course, I would like to know why the listener
thread suddenly doesn't accept anymore new connections. BTW, it occurs after
several succesful connections / disconnections. Did I forget to clear or
free something?
Basically, the code is like this:
Client:
fConn.Connect;
Try
fConn.Writeln('request');
Answer := fConn.Readln;
finally
fConn.Disconnect;
end;
Server (in the Execute handler):
procedure TPdmsTCPServer.PdmsExec(AThread: TIdPeerThread);
begin
Request := AThread.Connection.ReadLn;
<process request>
AThread.Connection.Writeln('answer');
end;
Thus the client Connects and Disconnects. Is that correct?
Any (more) help is very much appreciated!
Cheers,
Eric
| Quote: | What you describe suggests that the listener thread that accepts new
connections is terminating. But if you are servicing client data packets,
those are handled on a completely different thread then the listening
thread. The only way Ican see the listening thread terminating
prematurely
is if the server socket fails to accept a new connection.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Nov 17, 2003 10:24 pm Post subject: Re: TidTCPServer: thread sometimes killed |
|
|
"Squeller27" <squeller_5 (AT) hotmail (DOT) com> wrote
| Quote: | Basically, the code is like this:
|
There is nothing wrong with the code you have shown.
How often are the clients connecting to the server?
I would suggest assigning an OnListenException event handler to the server,
see if the listening thread is being aborted by an exception or not. That
will at least help narrow down the cause. If no exception is occuring, then
the only other way for the listening thread to terminate is if WinSock
itself is failing and the listening thread is detecting that.
Gambit
|
|
| Back to top |
|
 |
Squeller27 Guest
|
Posted: Mon Nov 17, 2003 10:44 pm Post subject: Re: TidTCPServer: thread sometimes killed |
|
|
Thanks again!
| Quote: | How often are the clients connecting to the server?
|
The connect and disconnect from the client will be executed frequently,
thousands of time! This shouldn't be a problem 'cause every connect is
followed by a disconnect.
| Quote: |
I would suggest assigning an OnListenException event handler to the
server,
see if the listening thread is being aborted by an exception or not. That
will at least help narrow down the cause. If no exception is occuring,
then |
I've considered that too. But as a newbie, I didn't know how to assign such
a handler. I've only found an onexecute, onconnect and ondisconnect property
to assign a handler to. So do you or anyone else know how to?
| Quote: | the only other way for the listening thread to terminate is if WinSock
itself is failing and the listening thread is detecting that.
Gambit
Eric |
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Nov 18, 2003 12:05 am Post subject: Re: TidTCPServer: thread sometimes killed |
|
|
"Squeller27" <squeller_5 (AT) hotmail (DOT) com> wrote
| Quote: | The connect and disconnect from the client will be executed frequently,
thousands of time! This shouldn't be a problem 'cause every connect is
followed by a disconnect.
|
It might be a problem, if you have a ton of connection attempts trying to
occur all at the same time. The server may not be able to handle that very
well.
| Quote: | I've considered that too. But as a newbie, I didn't know how to
assign such a handler.
|
OnListenException is a published event of TIdTCPServer, just use the Object
Inspector to assign a handler to it like any other event.
| Quote: | I've only found an onexecute, onconnect and
ondisconnect property to assign a handler to.
|
Earlier you said that you are using Indy 8. That is a very old version, you
should seriously consider upgrading to a newer version. TIdTCPServer in
Indy 9 has 8 published events:
OnAfterCommandHandler
OnBeforeCommandHandler
OnConnect
OnExecute
OnDisconnect
OnException
OnListenException
OnNoCommandHandler
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
|
|