Article View: borland.public.cppbuilder.internet.socket
Article #3294Re: Indy TCP C/S: Timeout , Concurrent access, Number of threads
From: Vladimir Stefanovic
Date: Thu, 06 Oct 2005 18:30
Date: Thu, 06 Oct 2005 18:30
100 lines
4089 bytes
4089 bytes
> Since you appear to be using Indy 9, then Connect() > has an ATimeout parameter. Hm... I'm using Indy that was shipped with BCB6 and I just cannot find 'ATimeout' parameter in Connect()? At line: IdTCPClient->Connect(5000); ... it says: "Extra parametar ..." What am I doing wrong? I thought it's Indy 9! >> How to know the number of active connections/threads? > > Use the Threads property, ie: > > TList *List = IdTCPServer1->Threads->LockList; > // look at List->Count > IdTCPServer1->Threads->UnlockList; Why you are using LockList/UnlockList? Is that a kind of protection when getting 'Count'? >> To be more precise, I want to limit the heavy operations >> in TIdTCPServer::OnExecute() so I want to do something >> like this /PSEUDO/: > > TIdTCPServer also has a MaxConnectionReply property > that can be used to send a reply back to the client telling > it that there are too many connections. This is interesting, but right now I cannot ask you anything before I try it in practice... > Also, your code suggests that you are not aware that the > OnExecute event is not called once per connection. It is > called over and over. I thought that ONE 'Connect()' on client side triggers ONE 'OnExecute()' on server side... But now, when I re-think, it's obvious that *cannot* be possible - that I say on client side: WriteInteger() WriteString() ...and expect that *only* ONE OnExecute() is trigered. But is it true that ONE Write...() trigeres ONE OnExecute()? >> // Sending the request length to server ... >> IdTCPClient->WriteInteger( REQUEST.Length() ); > > Why are you sending the string's length if you are not going to > send the string directly? Because I overlooked Write() method. >> TStringList *SL = new TStringList; >> SL->Add( REQUEST ); >> IdTCPClient->WriteStrings( SL ); >> delete SL; > > Why are you using a TStringList to send a single string? > [...]. > Based on the server code you have shown, you need to use > Write() instead of WriteStrings(): Because I overlooked Write() method. I searched for: WriteString(), not WriteStrings() but there wasn't it. I just overlooked Write(), that's why I needed to send the length of a string, and the argument of WriteStrings() was TString*, and that's why I needed a StringList. >> Memo->Lines->Add( REQUEST + " (received)" ); > <snip> >> Memo->Lines->Add( RESPONSE + " (prepared)" ); > <snip> >> Memo->Lines->Add( RESPONSE + " (sent)" ); > > That is not thread-safe on the server side. Yes, I was aware of that... I just wanted to resolve major problems first... > Now, with all of that said, I suggest a different approach > - make use of Indy's CommandHandler system. > < CODE > Thank you for the code. I must read about that, but it looks very useful. -- Best regards, Vladimir Stefanovic
Technical Details
Message-ID:
<43456cbf@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!novia!ecngs!feeder.ecngs.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<434503e6$1@newsgroups.borland.com> <43455dd4$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,cf1d5664f47b34d3 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu> Newsgroups: borland.public.cppbuilder.internet.socket References: <434503e6$1@newsgroups.borland.com> <43455dd4$1@newsgroups.borland.com> Subject: Re: Indy TCP C/S: Timeout , Concurrent access, Number of threads Date: Thu, 6 Oct 2005 20:30:27 +0200 Lines: 102 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 82.117.212.65 Message-ID: <43456cbf@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128623295 82.117.212.65 (6 Oct 2005 11:28:15 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!novia!ecngs!feeder.ecngs.de!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail