Article View: borland.public.cppbuilder.internet.socket
Article #573Re: Using TIdTCPServer
From: Peter
Date: Mon, 28 Jan 2008 18:26
Date: Mon, 28 Jan 2008 18:26
64 lines
3617 bytes
3617 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Peter" <piotrtrzeciak@yahoo.com> wrote in message
>news:4798db8f$1@newsgroups.borland.com...
>
>> When getting the binary data, first I get a piece that contains a
>> binary code that says "image", and then I have to read that image
>> (not knowing how big it is).
>
>In that situation, there are only three reliable ways to detect when
>arbitrary binary data has finished being sent:
>
>1) the server sends the data length beforehand (which it sounds like from
>yor descriptions that it is not)
>
>2) the server sends a unique terminator byte/sequence to mark the end of the
>image data. You would have to look for that terminator while reading so you
>don't accidentally receive too much data if another packet follows the image
>data right away.
>
>3) the server disconnects the connection at the end of the file.
>
>If the same socket connection is being used for both types of data
>transmissions, where your custom communication packets can arrive after the
>image is finished (without having to reconnect to the server), then #3 is
>not a viable option. It has to be doing either #1 or #2 to ensure the
>integrity of the communication.
>
>If the server is not doing any of those options, then the only other thing I
>can think of is to see if the image data itself has its own header that
>specifies the data size, assuming the same image format is being used each
>time.
>
>
>Gambit
>
>
Thanks!!!
Great points. I got most of it to work :-)
The only major issue for me that's remaining is the multithreading. The main server (TIdTCPServer) component is part of the TService application, and in it's main Execute thread, it is started like this:
iln_rcv_socket->Active = true;
while (!Terminated) {
ServiceThread->ProcessRequests(true);
}
iln_rcv_socket->Active = false;
This seems to be working ok, however, it appears that I can only get the first connection to come in ok, and the rest after that fail.
I also added TIdAntiFreeze component to the TService application, but I'm not sure if all the properties between TIdTCPServer and TIdAntiFreeze are set ok.
For TIdTCPServer I have:
ListenQueue: 200 (max for Win 2003 Server as I understand)
ReuseSocket: true
TerminateWait: 65535 (???)
For TIdAntiFreeze:
ApplicationHasPriority: true (???)
IdleTimeout: 250
OnlyWhenIdle: true
Also, I assume that all storage in OnExecute handler of the TIdTCPServer is local to the each thread.
Technical Details
Message-ID:
<479e2c75$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!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>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> NNTP-Posting-Host: 207.105.83.66 Message-ID: <479e2c75$1@newsgroups.borland.com> Date: 28 Jan 2008 11:26:45 -0700 X-Trace: newsgroups.borland.com 1201548405 207.105.83.66 (28 Jan 2008 11:26:45 -0700) Lines: 67 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail