Article View: borland.public.cppbuilder.internet.socket
Article #421Re: Using TIdTCPServer
From: Peter
Date: Fri, 01 Feb 2008 17:49
Date: Fri, 01 Feb 2008 17:49
51 lines
3638 bytes
3638 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Peter" <piotrtrzeciak@yahoo.com> wrote in message
>news:47a23116$1@newsgroups.borland.com...
>
>> When I do a very simple data send to the server, the sequence I get is:
>> 1. onConnect handler is invoked (no code, just log entry)
>> 2. onExecute handler is invoked (runs ok)
>> 3. onExecute handler is invokes AGAIN.
>
>That is normal behavior.
>
>> I assume on the same socket connection.
>
>Yes. Use the TIdContext parameter to verify that.
>
>> why is onExecute handler being invoked twice on the same socket
>> connection?
>
>Because it is supposed to. TIdTCPServer calls OnExecute in a continuous
>loop for the lifetime of the connection. You have your OnExecute code set
>up to read a single command and then exit. The server will loop around,
>call OnExecute again, read the next command (waiting as needed, raising an
>exception if error/disconnect occurs), exit, and repeat. This is the
>preferred way to use TIdTCPServer, so you are fine.
>
>
>Gambit
>
>
See... this is what I do not understand (excuse my ignorance here).
Shouldn't OnExecute be invoked only once per client connection?
1. A clinet connects.
2. The listener thread spawns a new thred and executes OnExecute handler in it.
3. Data exchange is performed within the OnExecute handler.
4. Either the client or the server closes the connection, and the thread ends.
5. The listener thread spawns a NEW thread for a new connection.
As such, I assume there should be a clear OnConnect/OnExecute/OnDisconnect sequence.
If I'm coming into the OnExecute for the second time with the same connection, how would I know where in the data I am?
To approach it from a different perspective and if the above is not true, how would I force the connection to be dropped completely when at the end of the OnExecute method?
Right now (as I shown in a different post), I have:
if (AContext->Connection->Connected()) {
AContext->Connection->Disconnect();
}
and the code inside of the if is always executed, but I do not get the OnDisconnect handler every time.
If the OnDisconnect handler is not invoked for some reason, the listener thread does not allow for any more connection anymore, and it does not yeld to the main application either (service is unstoppable).
Technical Details
Message-ID:
<47a369a7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com> <4798db8f$1@newsgroups.borland.com> <4798ef34$2@newsgroups.borland.com> <479e2c75$1@newsgroups.borland.com> <479e382e$1@newsgroups.borland.com> <479f4835$1@newsgroups.borland.com> <479f51f8$1@newsgroups.borland.com> <479f68b1$1@newsgroups.borland.com> <479f7070$1@newsgroups.borland.com> <479f9ae1$1@newsgroups.borland.com> <47a2265f$1@newsgroups.borland.com> <47a24592@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,452e664b18b0b56c X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Peter" <piotrtrzeciak@yahoo.com> Sender: "Peter" <piotrtrzeciak@yahoo.com> Reply-To: "Peter" <piotrtrzeciak@yahoo.com> Subject: Re: Using TIdTCPServer Newsgroups: borland.public.cppbuilder.internet.socket X-User-Info: 207.45.45.41 References: <478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> <4798cf30$1@newsgroups.borland.com> <4798db8f$1@newsgroups.borland.com> <4798ef34$2@newsgroups.borland.com> <479e2c75$1@newsgroups.borland.com> <479e382e$1@newsgroups.borland.com> <479f4835$1@newsgroups.borland.com> <479f51f8$1@newsgroups.borland.com> <479f68b1$1@newsgroups.borland.com> <479f7070$1@newsgroups.borland.com> <479f9ae1$1@newsgroups.borland.com> <47a2265f$1@newsgroups.borland.com> <47a24592@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <47a369a7$1@newsgroups.borland.com> Date: 1 Feb 2008 10:49:11 -0700 X-Trace: newsgroups.borland.com 1201891751 207.105.83.66 (1 Feb 2008 10:49:11 -0700) Lines: 53 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail