🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3295

Re: Indy TCP C/S: Timeout , Concurrent access, Number of threads

#3295
From: Vladimir Stefanovic
Date: Thu, 06 Oct 2005 19:05
74 lines
2892 bytes
Remy,

I modified my code to look like this, and now, really,
only the client closes the connection.

Also I used Write() instead of WriteStrings() and no
slow downs are present any more...

For the purpose of this example I didn't protected:

   Memo->Lines->Add()

... but I will in the real life.

I'm interested is the process of Writing/Reading
correct now?


--- Server ---

void __fastcall TIndyServerForm::IdTCPServerExecute(TIdPeerThread *AThread)
{
   // RECEIVING TASKS ...
   int BytesToRead = AThread->Connection->ReadInteger();
   AnsiString REQUEST = AThread->Connection->ReadString( BytesToRead );
   Memo->Lines->Add( REQUEST + " (received)" );

   // PROCESSING & PREPARING ANSWER TASKS ...
   AnsiString RESPONSE = FormatDateTime( "hh:mm AM/PM", Now() );
   Memo->Lines->Add( RESPONSE + " (prepared)" );

   // SENDING TASKS ...
   AThread->Connection->WriteInteger( RESPONSE.Length() );
   AThread->Connection->Write( RESPONSE );
   Memo->Lines->Add( RESPONSE + " (sent)" );
}


--- Client ---

void __fastcall TIndyClientForm::AskButtonClick(TObject *Sender)
{
   AskButton->Enabled = false;

   try
   {
      // CONNECTING
      IdTCPClient->Connect();

      // PREPARING REQUEST
      AnsiString REQUEST = "Can you please tell me what's the time?";
      Memo->Lines->Add( REQUEST + " (prepared)" );

      // SENDING TASKS
      IdTCPClient->WriteInteger( REQUEST.Length() );
      IdTCPClient->Write( REQUEST );
      Memo->Lines->Add( REQUEST + " (sent)" );

      // RECEIVING TASKS
      int BytesToRead = IdTCPClient->ReadInteger();
      AnsiString RESPONSE = IdTCPClient->ReadString( BytesToRead );
      Memo->Lines->Add( RESPONSE );
   }
   __finally
   {
      IdTCPClient->Disconnect();
      AskButton->Enabled = true;
   }
}


-- 
Best regards,
Vladimir Stefanovic 
Technical Details
Message-ID: <434574d8$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <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 21:05:03 +0200
Lines: 76
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: <434574d8$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1128625368 82.117.212.65 (6 Oct 2005 12:02:48 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail