🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: i need ideas/comments with tclientsocket

#3233
From: Hans Galema
Date: Mon, 31 Oct 2005 16:09
44 lines
2615 bytes
Jonathan Benedicto wrote:

 >     DataLength = min( Socket->ReceiveLength(), Data->Length );

If receivelength() > then Data->Length then your code will not read all
available bytes. Your code has to do that though otherwise your program
will hang.

>         char *Buffer = new char[ DataLength ];
> 
>         Socket->ReceiveBuf( Buffer, DataLength );
>         Data->DataStream->Write( Buffer, DataLength );
> 
>         delete[] Buffer;

You don't need to declare a temporary buffer. Just receive directly
in the TMemoryStream and care for a sufficient Size:

   int receivelength = Socket->ReceiveLength();

   if ( receivelength <= 0 )
       return;

   if ( MemoryStream->Position + receivelength >= MemoryStream->Size )
      MemoryStream->Size += receivelength + 1; // +1 is not needed I think

   int nread = Socket->ReceiveBuf (
	((char*)MemoryStream->Memory) + MemoryStream->Position, receivelength );


>     if( Data->Length == 0 )
>     {
>         // process your command here.
>         // it is stored in Data->DataStream.
>         // the stream is cleared once you've finished.

If you check for Data->Length == 0 then you are not allowing the sender
to send more than one message at a time. If the sender sends more
messages at once than the second message can have partly come in with
the first message. Better check if a complete message came in.
You then cannot automatically clear the stream also because of a next message
already partly present.

Hans.
Technical Details
Message-ID: <43664213$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43662baf$1@newsgroups.borland.com> <43663272$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,5c33b8c6a9ca7fdb
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 31 Oct 2005 17:09:50 +0100
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: i need ideas/comments  with tclientsocket
References: <43662baf$1@newsgroups.borland.com> <43663272$1@newsgroups.borland.com>
In-Reply-To: <43663272$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 145.98.201.248
Message-ID: <43664213$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1130775059 145.98.201.248 (31 Oct 2005 08:10:59 -0700)
Lines: 44
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail