Article View: borland.public.cppbuilder.internet.socket
Article #4924Re: how to send buffer size message and buffer
From: hans galema
Date: Wed, 17 Nov 2004 11:15
Date: Wed, 17 Nov 2004 11:15
37 lines
2285 bytes
2285 bytes
duncan wrote:
> ClientSocket is using Socket->SendBuf(memory_stream->Memory, (int)size);
>
> The message is picked up in the ServerSocket OnRead event and this is where the message is processed.
> However I do not know the size of the incomming buffer. I have
> read that this needs to be sent also, however if I send this then the ServerSocket OnRead picks up on this also. So I am unsure how to send the info or how to code my
> ServerSocket::OnRead event to handel the size and the actual buffer.
You have to keep track on what is received yourself.
Sender:
int size = ....;
Socket->SendBuf(&size, sizeof(size);
Socket->SendBuf(memory_stream->Memory, size);
Receiver:
int nbytes = Socket->ReceiveLength();
if ( nbytes <= 0 ) return;
static int size = 0; // you could make it private too.
if ( size == 0 )
Socket->ReceiveBuf ( &size, sizeof (size );
int nreceived = Socket->ReceiveBuf ( buffer, size );
compare nreceived with size and nbytes
and repeat a call to ReceiveBuf() or wait for the next OnRead()
when a message is processed set size to 0
Hans.
Technical Details
Message-ID:
<419b32cf$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!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<419b3068$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,e51687cce2165a07 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 17 Nov 2004 12:15:28 +0100 From: hans galema <notused@notused.nl> User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: how to send buffer size message and buffer References: <419b3068$1@newsgroups.borland.com> In-Reply-To: <419b3068$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <419b32cf$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1100690127 129.125.201.248 (17 Nov 2004 03:15:27 -0700) Lines: 37 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news-hub.cableinet.net!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail