🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: packet contatenation

#3197
From: Joe Black
Date: Wed, 26 Oct 2005 08:08
74 lines
3644 bytes
Remy Lebeau (TeamB) wrote:
> "Joe Black" <nospam@newsgroup.com> wrote in message
> news:435e5931$1@newsgroups.borland.com...
> 
> 
>>For some reason though several packets seem to get
>>concatenated together to form one larger packet
> 
> 
> That is perfectly normal socket behavior.  A socket buffers all outgoing
> data until either the buffer is full or until the socket has no pending data
> waiting to be sent.
> 
> 
>>if I slow down the transmit thread to say every 200ms this
>>problems dissapears
> 
> 
> Yes, because you are allowing the socket to have some time to clear its
> internal buffer before more data is passed to it.
> 
> 
>>Is there anyway to determine whether the last packet was
>>sent before I attempt to send the next one
> 
> 
> No.  But that is not needed in the first place.  TCP is a stream transport.
> It doesn't care what the contents of the data is.  It sends a stream of
> arbitrary bytes.  So you are responsible for formatting your outgoing data
> in such a way that the receiver knows where one packet ends and the next
> begins.  There are three ways to do that:
> 
> 1) send messages that are all the same byte size.  The receiver reads the
> necessary number of bytes and then processes them.
> 
> 2) preceed each message with a fixed-sized length value.  The receiver first
> reads the necessary number of bytes to receive the length and then continues
> reading the specified number of bytes to finish the message.
> 
> 3) Place a unique terminator sequence of bytes at the end of a message.  The
> terminator cannot appear in the message contents at all.  This way, the
> receiver continues reading bytes until the terminator is encountered.
> 
> In all three situations, you have to code your reading to handle three
> different scenerios when a read event occurs:
> 
> 1)  no bytes are available at all
> 
> 2) fewer bytes are received than are needed for a complete message,
> requiring you to wait for another read event in order to receive more bytes
> for that message.
> 
> 3) bytes from multiple messages are received at one time.
> 
> In all read events, you should buffer the received bytes and then process
> and remove any complete messages that are in buffer, leaving any incomplete
> messages in the buffer for later processing.
> 
> 
> Gambit
> 
> 


Hi Remy,

Many thanks for your response, it covers all the areas I'm having the 
trouble with, I had an feeling I was going to have to put the data back 
together after I recieved it but I couldn't find the right sort of 
information about it, my googleing skills must be lacking at the moment :-).

Thanks again

Joe
Technical Details
Message-ID: <435f3856$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <435e5931$1@newsgroups.borland.com> <435e9db5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,de4e39df019561af
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Wed, 26 Oct 2005 09:08:59 +0100
From: Joe Black <nospam@newsgroup.com>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: packet contatenation
References: <435e5931$1@newsgroups.borland.com> <435e9db5$1@newsgroups.borland.com>
In-Reply-To: <435e9db5$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 80.177.44.177
Message-ID: <435f3856$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1130313814 80.177.44.177 (26 Oct 2005 01:03:34 -0700)
Lines: 74
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail